What’s new in TypeScript 5.0

Latest upgrade to Microsoft’s strongly typed JavaScript, rebuilt to use ECMAScript modules, promises to be smaller, faster, and simpler.

woman holding up 5 fingers number 5 top five
Getty Images

TypeScript 5.0, an update to Microsoft’s strongly typed JavaScript variant, is now available as a production release, Microsoft announced March 16. With the upgrade, TypeScript has been rebuilt to use ECMAScript modules. TypeScript 5.0 also modernizes decorators for class customization.

ECMAScript modules reduce package size and boost performance. Decorators, an upcoming ECMAScript feature, allow for customizing classes and their members in a reusable way, Microsoft noted in a March 1 blog post.

Decorators can be used on methods, properties, getters, setters, and auto-accessors. Classes can be decorated for subclassing and registration. While TypeScript previously supported experimental decorators, these were modeled on a much older version of the decorators proposal. TypeScript 5.0 will permit decorators to be placed before or after export and export default, a change made since the January 26 beta release of the new version. 

Also in TypeScript 5.0, developers now can add a const modifier to a type parameter declaration to cause const-like inferences to be the default. The update also now allows the extends field to take multiple entries, and it makes all enums union enums by creating a unique type for each computed member. This means all enums can be narrowed and have their members referenced as types.

TypeScript 5.0 features changes across 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: The new bundler module resolution option now can only be used when the --module option is set to esnext. This ensures that import statements written in input files will not be transformed to require calls before the bundler resolves them.

Despite the revamp to embrace ECMAScript modules, Microsoft said TypeScript 5.0 was not a disruptive release, and everything developers know is still applicable. TypeScript 5.0 can be accessed through NuGet or by running the following command:

npm install -D typescript

Also in TypeScript 5.0:

  • A –-verbatimModuleSyntax capability simplifies imports and exports, keeping imports or exports without a type modifier while dropping anything using the type modifier.
  • A new JSDoc tag, @satisfies, catches type mismatches while preserving the original type of an expression, enabling developers to use values more precisely in code. Many developers use TypeScript to type-check JavaScript code using JSDoc annotations. Also, JSDoc now can declare overloads with a new @overload tag.
  • Correctness changes and deprecations are offered for less-used flags.
  • TypeScript now targets ECMAScript 2018. For Node users, this means a minimum version requirement of at least Node.js 10.

TypeScript 5.0 follows the November release of TypeScript 4.9, which featured a satisfies operator to catch errors. TypeScript turned 10 years old in October 2022. The production release of TypeScript 5.0 follows release candidate and beta release stages, with the beta arriving January 26 and the RC appearing on March 1.

Copyright © 2023 IDG Communications, Inc.