TypeScript 5.3 adds support for import attributes

By Akash
on 14-10-2023 11:16 AM

ECMAScript import attributes will support additional types of modules in a common way across JavaScript environments, starting with JSON modules.

TypeScript 5.3, an upgrade to Microsoft’s strongly typed JavaScript variant now in beta, is set to support updates to an import attributes proposal for ECMAScript modules.The ECMA standards proposal features an inline syntax for module import statements to pass information alongside the module specifier. These attributes will support additional types of modules in a common way across JavaScript environments, beginning with JSON modules.
In an October 3 bulletin on the TypeScript 5.3 beta, Microsoft said one use case of import attributes was to provide information about the expected format of a module at runtime. In the example cited, Microsoft said the contents of attributes were not checked by TypeScript because they are host-specific and left alone so that browsers and runtimes can handle them.

Import attributes are an evolution an earlier proposal, import assertions, that were implemented in TypeScript 4.5 in November 2021. The most obvious difference is the use of the with keyword over the assert keyword. A less visible difference is that runtimes now can use attributes to guide the resolution and interpretation of import paths, while import assertions only could assert some characteristics after loading a module. Plans call for deprecating the old syntax for import assertion in favor of the proposed standard for import attributes.