TypeScript 5.5: The New Features and Changes are Here

TypeScript 5.5: The New Features and Changes are Here
Photo by La-Rel Easter / Unsplash

TypeScript 5.5, the latest version of Microsoft's statically typed JavaScript variant, has officially been released, bringing with it a host of enhancements and new features designed to improve performance, reduce package size, and add new functionalities. This release is particularly notable for its support of new Set methods in ECMAScript and improvements in regular expression checking.

Release Details and Availability

Released on June 20, TypeScript 5.5 is now available through Nuget or by using the command: npm -D typescript. The development cycle for this version began with a beta release on April 25, followed by a release candidate on June 6. Each stage of the release process incorporated user feedback and extensive testing to ensure a robust and stable final product.

Reverted Changes and Future Plans

Since the release candidate, Microsoft has temporarily rolled back a change that relied on package.json to determine the module format of a file. This change, although well-intentioned, was found to disrupt workflows and impose a heavy file-watching load, particularly in larger projects. This feedback was taken seriously, and the change was reverted to avoid any negative impact. Microsoft plans to reintroduce a more refined version of this feature in TypeScript 5.6, along with optimizations to better handle the monitoring of non-existent files.

New Set Methods

One of the most significant additions in TypeScript 5.5 is the support for new Set methods proposed for JavaScript. These methods, which include union, intersection, and difference, allow developers to perform set operations more intuitively. For instance, the union method takes another Set and returns a new Set containing all elements from both Sets. Similarly, the intersection method returns a new Set with elements common to both Sets, and the difference method returns a Set with elements that are in one Set but not the other. Additionally, the isSubsetOf method checks if a Set is a subset of another and returns a boolean result. These methods enhance the functionality of Sets in TypeScript, making complex data manipulations simpler and more efficient.

Regular Expression Checking

TypeScript 5.5 has introduced a more lenient approach to regular expression checking while maintaining strict error handling for questionable escapes as specified in ECMAScript’s Annex B. This change aims to balance flexibility and correctness, allowing developers more freedom in writing regular expressions without sacrificing error detection. This enhancement ensures that common mistakes in regular expressions are caught early, improving code reliability and reducing debugging time.

Performance Optimizations

Performance has been a major focus in this release, with several optimizations aimed at reducing build times and improving the overall developer experience. One notable improvement is in the transpileModule function, where unnecessary checks have been skipped, leading to faster compilation times. Additionally, optimizations in filtering contextual types help speed up the build process and iteration times, allowing developers to see the results of their changes more quickly.

Monomorphization and API Enhancements

TypeScript 5.5 includes extensive monomorphization work for the language service and public API. Monomorphization involves creating specific, optimized versions of functions for different types, which can significantly improve performance. This work, previously applied to Node and Symbol objects in TypeScript 5.0, ensures a consistent set of properties with a predictable initialization order, enhancing both the editor experience and the performance of build tools that utilize the TypeScript API.

Package Size Reduction

Another significant improvement in TypeScript 5.5 is the substantial reduction in overall package size. The disk footprint has been reduced from 30.2 MB to 20.4 MB, and the packed size has decreased from 5.5 MB to 3.7 MB. These reductions make TypeScript more efficient to install and use, particularly in environments with limited storage or bandwidth.

Improved Declaration File Generation

As part of efforts to enable isolatedDeclarations, Microsoft has enhanced the way TypeScript generates declaration files. The improvements allow TypeScript to more frequently copy input source code directly when producing declaration files, streamlining the process and reducing potential errors.

Basic Syntax Checking for Regular Expressions

Until now, TypeScript typically ignored most regular expressions in code due to their extensible grammar. With TypeScript 5.5, basic syntax checking has been introduced, meaning that common problems in regular expressions will now be detected earlier in the development process. This change helps developers catch errors that might otherwise go unnoticed until runtime, improving code quality and reliability.

Enhanced Type Inference and Control Flow Narrowing

TypeScript 5.5 brings enhancements to type inference, particularly in deducing that a function returns a type predicate under certain conditions. This improvement helps developers write more precise and accurate type declarations, leading to better type checking and fewer runtime errors. Additionally, control flow narrowing for constant indexed accesses has been improved. TypeScript can now narrow expressions in cases where both the object and key are constant, allowing for more precise and optimized code.

Simplified ECMAScript Module Consumption

To make consuming ECMAScript modules easier, TypeScript 5.5 now allows named imports from the TypeScript package in Node.js. This change simplifies the module import process and aligns TypeScript more closely with ECMAScript standards. Furthermore, a new @import comment tag has been introduced, using the same syntax as ECMAScript imports, making it easier for developers to transition between the two.

New TranspileDeclaration API

TypeScript 5.5 also introduces a new transpileDeclaration API. This API is designed to generate a single declaration file from input source text, similar to how the transpileModule API compiles a single TypeScript file. This addition provides developers with a straightforward way to create declaration files, simplifying the process of generating type definitions for TypeScript projects.