微软宣布发布TypeScript 3.0:在JSX 中支持 defaultProps

  据悉,微软宣布发布 TypeScript 3.0 正式版。官方称,虽然版本号是一个大变化,但 3.0 版本几乎没有破坏性的变更(这意味着我们可以很轻松地升级到该版本),3.0 引入了一种新的灵活且可扩展的方式来构建项目、提供对参数列表进行操作新的强大支持能力、强制显式检查的新类型、更好的 JSX 支持、整体更好的错误处理,等等。

  下面简单说说值得关注的更新。

微软宣布发布TypeScript 3.0:在JSX 中支持 defaultProps

  项目引用(Project references)

  这是 3.0 版本中引入的一个新概念。考虑这样一个场景 —— 对于开发者而言,为库或应用程序提供几个不同的构建步骤是相当常见的。也许你的代码库有一个 src 和一个测试目录。也许你将前端代码放在一个名为 client 的文件夹中,将 Node.js 后端代码放在名为 server 的文件夹中,每个文件夹都从共享文件夹中导入代码。也许你使用所谓的“monorepo”并且有许多项目以复杂的方式相互依赖。

  官方表示,针对上述的场景,他们为 TypeScript 3.0 开发了最重大的功能之一 ——“项目引用(project references)”。

  项目引用允许 TypeScript 项目依赖于其他 TypeScript 项目 —— 特别是允许 tsconfig.json 文件引用其他 tsconfig.json 文件。指定这些依赖项可以更容易地将代码拆分为更小的项目,因为它为 TypeScript(及其周围的工具)提供了一种理解构建顺序和输出结构的方法。这意味着更快的构建可以逐步工作,并支持跨项目导航、编辑和重构。由于 3.0 奠定了基础并公开了 API,因此任何构建工具都能够提供这一功能。

  在JSX 中支持 defaultProps

  该特性使得调用者可以通过不需要某些参数来更轻松地使用函数。

  破坏性变更API 的破坏性变更

  The deprecated internal method LanguageService#getSourceFile has been removed, as it has been deprecated for two years. See #24540.

  The deprecated function TypeChecker#getSymbolDisplayBuilder and associated interfaces have been removed. See #25331. The emitter and node builder should be used instead.

  The deprecated functions escapeIdentifier and unescapeIdentifier have been removed. Due to changing how the identifier name API worked in general, they have been identity functions for a few releases, so if you need your code to behave the same way, simply removing the calls should be sufficient. Alternatively, the typesafe escapeLeadingUnderscores and unescapeLeadingUnderscores should be used if the types indicate they are required (as they are used to convert to or from branded __String and string types).

  The TypeChecker#getSuggestionForNonexistentProperty, TypeChecker#getSuggestionForNonexistentSymbol, and TypeChecker#getSuggestionForNonexistentModule methods have been made internal, and are no longer part of our public API. See #25520.

tag:支持文件代码项目参数功能

相关内容