TypeScript 5.3 has been released

TypeScript 5.3 has been released, introducing support for import attributes in ECMAScript modules. This update from Microsoft, which enhances the strongly typed JavaScript variant, marks a significant development in the handling of module imports.

A key feature of TypeScript 5.3 is its reinforcement of the ECMAScript import attributes proposal, which presents an inline syntax for module import statements, allowing the inclusion of information alongside the module specifier. These attributes, initially focused on JSON modules, establish a standardized approach to supporting various module types across JavaScript environments.

Import attributes serve multiple purposes, with one notable use case being the provision of information about the expected format of a module at runtime. Microsoft emphasizes that TypeScript does not validate the contents of attributes, as they are host-specific and intended for interpretation by browsers and runtimes.

This concept of import attributes builds upon the earlier implementation of import assertions in TypeScript 4.5, introduced in November 2021. The distinction between the two lies in the use of the “with” keyword instead of “assert” and the expanded capabilities of attributes to guide the resolution and interpretation of import paths. Import assertions, by contrast, were limited to asserting certain characteristics after module loading. Microsoft plans to deprecate the old syntax for import assertions in favor of the emerging standard for import attributes.

Additionally, TypeScript 5.3 introduces the option to prioritize type-only auto-imports when feasible. Previously, auto-imports generated by TypeScript in type positions included a type modifier based on developer settings. The recent change allows for customization through editor-specific options.

Beyond these major changes, TypeScript 5.3 brings several other enhancements, including support for the resolution-mode attribute in import types, improved narrowing based on conditions in switch (true) case clauses, and refined inspection of super property accesses and method calls for alignment with class fields, resulting in more accurate type-checking errors.

Moreover, TypeScript inlay hints now facilitate seamless navigation to the definition of types, streamlining code exploration. The compiler, when running TypeScript via tsc, optimizes parsing by avoiding JSDoc processing, leading to reduced parsing time and memory usage, along with enhanced garbage collection efficiency for comments storage.

Consolidation efforts between tsserverlibrary.js and typescript.js have been undertaken, promoting a more cohesive development environment. Additionally, TypeScript now accommodates the customization of the instanceof operator behavior in JavaScript by checking for a specific method named by Symbol.hasInstance on the right side of the operator, enhancing type narrowing based on type predicate functions.