TypeScript 5.0, a planned update from Microsoft strongly-typed JavaScript variantis now available in a Release Candidate (RC) build, with a production release scheduled for March 14. The update aims to modernize decorators for class customization.
Decorators, an upcoming ECMAScript feature, allow classes and their members to be customized in a reusable way, Microsoft noted in a blog post announcing the RC. Decorators can be used on methods, properties, getters, setters, and auto-accessors. Classes can be decorated for subgrading and enrolling. While TypeScript previously supported experimental decorators, these were modeled after a much older version of the decorators proposal. TypeScript 5.0 will allow decorators to be placed before or after export and export by default, a change made since the January 26 beta of the new release.
Also in TypeScript 5.0, developers can now add a const
modifier to a type parameter declaration to cause cons
t-type inferences are the default. The update also now allows the extends
to accept multiple inputs, and it turns all enumerations into enumerations by creating a unique type for each calculated member. This means that all enumerations can be collapsed and their members are referenced as types.
TypeScript 5.0 features changes in code structure, data structures, and algorithmic extensions, intended to speed up the entire experience of using TypeScript, even installation. Overall, TypeScript 5.0 is intended to make the language smaller, faster, and simpler. Another change since the beta: new bundler module resolution option now can only be used when the --module
option is set to esnext
. This ensures that import
instructions written in input files will not be transformed into require
calls before the consolidator resolves them.
No other changes are expected in TypeScript 5.0 except for critical bug fixes. TypeScript 5.0 release candidate can be accessed via NuGet or by running the following command:
npm install typescript@rc
Also in TypeScript 5.0:
- Better support is offered for ESM (ECMAScript module) projects in Node and bundlers.
- A
–-verbatimModuleSyntax
The ability simplifies imports and exports, maintaining imports or exports withouttype
modifier while dropping anything using thetype
modifier. - A new JSDoc tag,
@satisfies
, detects type mismatches while preserving an expression’s original type, allowing developers to use values more accurately in code. Many developers use TypeScript to verify JavaScript code using JSDoc annotations. Additionally, JSDoc can now declare overloads with a new@overload
label. - Accuracy changes and write-downs are proposed for less used indicators.
- TypeScript now targets ECMAScript 2018. For Node users, this means a minimum required version of at least Node.js 10.
TypeScript 5.0 follows the November release of Typescript 4.9which included a satisfies
operator to detect errors. Manuscript was 10 years old in October 2022.
Copyright © 2023 IDG Communications, Inc.