What's New in TypeScript 5.3
Microsoft advanced TypeScript to version 5.3 with a bevy of changes affecting everything from import attributes to interactive inlay hints for types, along with multiple optimizations.
Here's a summary of the release highlights as presented
- Import Attributes: The release supports the latest updates to the import attributes proposal, which allows specifying additional information about the expected format of a module to the runtime. The syntax uses the
with keyword instead of the deprecated
- Stable Support
resolution-mode in Import Types: TypeScript 5.3 allows controlling whether a specifier should be resolved via
require semantics using a
resolution-mode attribute in
/// reference types="..." /> declarations. This feature was introduced in TypeScript 4.7 as experimental and is now stable.
switch (true) Narrowing: The latest update improves the type narrowing behavior of
switch (true) statements, which are often used as a replacement for
else if chains. The compiler can now narrow the types of variables based on the conditions in each
instanceof Narrowing Through
Symbol.hasInstance Checks: TypeScript 5.3 also improves the type narrowing behavior of
instanceof checks by taking into account the
Symbol.hasInstance method, which allows customizing the behavior of the
instanceof operator for user-defined classes. The compiler can now narrow the types of variables based on the return value of the
- Checks for super Property Accesses on Instance Fields: TypeScript 5.3 introduces stricter checks for property accesses on
super in classes with instance fields. The compiler will now report an error when accessing a property on
super that is not a method or a getter, as this can lead to unexpected behavior at runtime.
- Optimizations by Skipping JSDoc Parsing: v5.3 improves the performance of the compiler and the language service by skipping the parsing of JSDoc comments in
.d.ts files unless explicitly requested by the
--allowJs flags. This can reduce the memory usage and startup time of the compiler.
- Optimizations by Comparing Non-Normalized Intersections: TypeScript 5.3 also improves the performance of the compiler by avoiding unnecessary normalization of intersection types when comparing them for equality or assignability. This can reduce the number of expensive type operations and speed up type-checking.
- Consolidation Between
typescript.js: TypeScript 5.3 consolidates the functionality of the
typescript.js files, which are used to power the TypeScript language service and the TypeScript compiler, respectively. This can simplify the development and maintenance of TypeScript tools and plugins.
As far as those breaking changes and correctness improvements, they include changes in
lib.d.ts and enhanced checks for
super accesses on instance properties.
Microsoft expects to ship TypeScript 5.4 near the end of February 2024. The GitHub repo for v5.4 milestones shows 27 percent completion, with 26 open items and 10 closed items. As can be seen in the partial graphic above, the milestones include bugs, breaking changes and more.
David Ramel is an editor and writer for Converge360.