首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

微软TypeScript 3.0 正式发布:引入“项目引用”新概念

北京时间7月31日,微软宣布推出 TypeScript 3.0 正式版。

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

下面简单说说值得关注的更新,更详细的更新说明请移步至?发布说明

项目引用(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.

相关链接

发布说明?https://blogs.msdn.microsoft.com/typescript/2018/07/30/announcing-typescript-3-0/ TypeScript 3.0 新特性?https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#typescript-30 TypeScript 3.0 文档?https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html 破坏性变化?https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#typescript-30

下载地址

npm Visual Studio 2015 plugin Visual Studio 2017?(Select new version in project options) NuGet package

  • 发表于:
  • 原文链接http://news.51cto.com/art/201807/580050.htm
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券
http://www.vxiaotou.com