Press "Enter" to skip to content

TypeScript 5.0 retools decorators | InfoWorld

TypeScript 5.0, a planned update to Microsoft’s Strongly Typed JavaScript variant, is now available in a Release Candidate (RC) version, with a production release scheduled for March 14. The update aims to modernize the decorators for class customization.

Decorators, an upcoming ECMAScript feature, let you customize classes and their members 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 subclassing and logging. While TypeScript previously supported experimental decorators, these were modeled on a much older version of the decorator proposal. TypeScript 5.0 will allow decorators to be placed before or after export and default export, a change made since the new version’s January 26 beta release.

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

TypeScript 5.0 introduces changes to code structure, data structures, and algorithmic extensions, intended to speed up the entire experience of using TypeScript, including installation. Overall, TypeScript 5.0 aims to make the language smaller, faster, and simpler. Another change from the beta: the new package module resolution option can now only be used when the --module option is set to esnext. This ensures that import statements written to input files will not be transformed into require calls before the wrapper resolves them.

Also Read:  Oracle’s new Java subscription model to cost a lot more: Gartner

No further changes are expected in TypeScript 5.0, except for critical bug fixes. The 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 provided for ESM (ECMAScript Module) projects in Node and bundlers.
  • TO –-verbatimModuleSyntax capacity simplifies imports and exports, keeping imports or exports without a type modifier while dropping anything using the type modifier
  • A new JSDoc tag, @satisfies, detects type mismatches and preserves the original type of an expression, allowing developers to use values ​​more precisely in code. Many developers use TypeScript to type check JavaScript code using JSDoc annotations. Also, JSDoc can now declare overloads with a new @overload label.
  • Correction 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 detect errors. TypeScript turned 10 years old in October 2022.

Copyright © 2023 IDG Communications, Inc.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *