TypeScript 5.3 Debuts Import Attribute Support - aspirestream.ltd

TypeScript 5.3 Debuts Import Attribute Support

May 15, 2024 Arnold 0 Comments

Microsoft’s TypeScript 5.3, a significant update to the JavaScript superset known for its strong typing, introduces support for import attributes for ECMAScript modules. This latest release also brings various enhancements, including stable support for resolution mode in import types and interactive inlay hints for types.

Released on November 20, TypeScript 5.3 is now available for production use through NuGet or NPM. To access it via NPM, developers can use the following command:

npm install -D typescript

The highlight of TypeScript 5.3 is its backing of the latest updates to the ECMA import attributes proposal. This proposal aims to introduce an inline syntax for module import statements, enabling the passing of information alongside the module specifier. Initially, these attributes will facilitate the support of additional module types, starting with JSON modules, in a standardized manner across various JavaScript environments.

One notable use case highlighted by Microsoft is the provision of runtime information about the expected format of a module. Notably, TypeScript doesn’t validate the contents of these attributes, as they are host-specific and intended for handling by browsers and runtimes.

Import attributes represent an evolution from the earlier import assertions proposal, which TypeScript implemented in version 4.5. The key distinction lies in the use of the “with” keyword instead of “assert.” Additionally, runtime environments can now utilize attributes to guide the resolution and interpretation of import paths, whereas import assertions could only assert characteristics post-loading.

In TypeScript 5.3, there’s also a new option introduced to prefer type-only auto-imports whenever feasible. Previously, TypeScript would add a type modifier based on developer settings when generating auto-imports for items in a type position. With the recent update, TypeScript enables an editor-specific option to handle this behavior.

This production release follows a beta release on October 3 and a release candidate on November 3. Its predecessor, TypeScript 5.2, was released on August 24.

Other notable features and improvements in TypeScript 5.3 include support for the resolution-mode attribute for import types, enhanced narrowing capabilities based on conditions in switch clauses, and more thorough inspections of super property accesses and method calls. Additionally, TypeScript inlay hints now support jumping to the definition of types, enhancing code navigation. Furthermore, improvements have been made to parsing efficiency when running TypeScript via tsc, reducing parsing time and memory usage.

leave a comment