ECMAScript modules reduce the packet size and improve performance. Decorators, an upcoming ECMAScript feature, let you customize 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 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.
Despite the revamp to adopt ECMAScript modules, Microsoft said that TypeScript 5.0 was not a disruptive release and that everything developers know is still applicable. TypeScript 5.0 can be accessed via NuGet or by running the following command:
npm install -D typescript
Also in TypeScript 5.0:
–-verbatimModuleSyntaxcapacity simplifies imports and exports, keeping imports or exports without a
typemodifier while dropping anything using the
- A new JSDoc tag,
- 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. The production release of TypeScript 5.0 follows both the release candidate and beta release stages, with the beta arriving on January 26 and the RC appearing on March 1.
Copyright © 2023 IDG Communications, Inc.
Be First to Comment