Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News TypeScript 5 GA Extends Decorators, Stabilizes New Module Resolution Option, and More

TypeScript 5 GA Extends Decorators, Stabilizes New Module Resolution Option, and More

This item in japanese

After announcing TypeScript 5.0 Beta three months ago, TypeScript 5 has finally reached general availability. Among the most relevant changes are extended support for decorators to enable their placement before or after export and export defaults, the new bundler module resolution option, and more.

InfoQ already provided a brief intro to the salient new features brought by TypeScript 5 after its beta was announced. Decorators are by far the biggest new feature, making it possible to decorate classes and their members to make them more easily reusable. For example, you could create a loggedMethod decorator to add some logging behaviour to an existing function. Decorators are just syntactic glue aiming to simplify the definition of higher order functions.

The mentioned change to decorators, making it possible to place their definition before or after export and export defaults is basically a compatibility requirement with future releases of ECMAScript/JavaScript.

TypeScript 5 introduced a new bundler module option, named --moduleResolution bundler aimed to improve coexistence with modern bundlers like Vite, esbuild, swc, Webpack, Parcel, and others. TypeScript 5 GA makes this option usable only with esnext modules.

This was done to ensure that import statements written in input files won’t be transformed to require calls before the bundler resolves them, whether or not the bundler or loader respects TypeScript’s module option.

The older bundler option are on the contrary more suitable for packages to be distributed through npm.

While TypeScript 5.0 is the first to use the major version 5, it is useful to recall that TypeScript does not follow semantic versioning, meaning that moving from TypeScript 4.9 to 5.0 is not qualitatively different than going from 4.8 to 4.9.

This does not mean though that TypeScript 5 does not introduces a number of breaking changes and deprecations, like the complete overhaul of the enum type, which could break existing code.

About the Author

Rate this Article