宣布 TypeScript 5.4 - TypeScript

主要观点:宣布 TypeScript 5.4 发布,介绍其新特性、自测试版和候选版本以来的更新、各特性的详细内容、从 TypeScript 5.0 开始的即将弃用项以及 notable behavioral changes 等,还提及接下来的 TypeScript 5.5 计划。
关键信息

  • 新特性包括 preserved narrowing in closures following last assignments、NoInfer utility type、Object.groupBy 和 Map.groupBy、支持 require() calls、Checked Import Attributes and Assertions、Quick Fix for Adding Missing Parameters、Auto-Import Support for Subpath Imports 等。
  • 自测试版以来更新了发布说明,包含 notable behavioral changes;自候选版本以来记录了新的 auto-import 支持。
  • TypeScript 5.0 弃用了一些选项和行为,5.4 是其继续正常运行的最后版本,5.5 起将成为硬错误。
  • notable behavioral changes 涵盖 lib.d.ts 变化、更准确的条件类型约束、更积极地减少类型变量与原始类型的交集、改进对带有插值的模板字符串的检查、当仅类型导入与本地值冲突时的错误、新的枚举可赋值性限制、枚举成员的名称限制、更好的映射类型保留等。
    重要细节
  • preserved narrowing in closures following last assignments 利用函数中最后赋值点使类型缩小更智能,但变量在嵌套函数中赋值时不生效。
  • NoInfer utility type 可阻止 TypeScript 推断类型,解决一些类型推断问题。
  • Object.groupBy 和 Map.groupBy 为 JavaScript 的新静态方法添加声明,Object.groupBy 生成对象,Map.groupBy 生成 Map。
  • 支持 require() calls 需设置 module 为 preserve 并结合 moduleResolution bundler 等选项,准确模拟 bundlers 和运行时的行为。
  • Checked Import Attributes and Assertions 可让运行时更准确描述导入属性。
  • Quick Fix for Adding Missing Parameters 可快速为调用时参数过多的函数添加新参数。
  • Auto-Import Support for Subpath Imports 支持 Node.js 中的 subpath imports。
  • notable behavioral changes 涉及多个方面的行为调整和限制,对代码可能有影响。
  • 接下来将致力于 TypeScript 5.5,目标发布日期公开,可尝试 nightly 版本或在 Visual Studio Code 中使用最新版本。
阅读 8
0 条评论