TypeScript 5.5, the latest version of Microsoft’s strongly typed JavaScript variant, has graduated to a release candidate (RC) stage. The update, which brings improvements ranging from performance and size optimizations to regular expression checking, recently added support for ECMAScript’s new Set methods.
The TypeScript 5.5 release candidate was introduced June 6 and can be accessed through Nuget or the following command: npm -D typescript@rc
. A beta release was introduced April 25 and the final release is planned for June 18.
Since the beta, TypeScript 5.5 added support for the new Set methods proposed for JavaScript. Some of these methods, such as union
, intersection
, and difference
, take another Set
and return a new Set
as the result. Other methods, such as isSubsetOf
, take another Set
and return a boolean
.
Also new in the release candidate, TypeScript’s regular expression checking has been made slightly more lenient while still erroring on questionable escapes that are allowed only per ECMAScript’s Annex B. The TypeScript 5.5 (RC) also features more performance optimizations, including skipped checking in transpileModule
and optimizations in filtering contextual types that can lead to faster build and iteration times.
TypeScript 5.5 includes numerous other improvements that were previously available in the beta release. For performance and size, monomorphization work has been done for the language service and public API. With monomorphism, the editor experience and build tools using the TypeScript API will get faster, TypeScript’s authors said. This was the same work previously done for Node and Symbol objects in TypeScript 5.0 to ensure they had a consistent set of properties with a consistent initialization order.
TypeScript 5.5 also features a significant reduction in overall package size. The disk footprint has been reduced from 30.2 MB to 20.4 MB, and the packed size from 5.5 MB to 3.7 MB. As part of work to enable isolatedDeclarations
, Microsoft has improved how often TypeScript can directly copy input source code when producing declaration files.
TypeScript 5.5 introduces basic syntax checking on regular expressions. Until now, TypeScript typically skipped over most regular expressions in code, because regular expressions technically have an extensible grammar and TypeScript never made an effort to compile regular expressions to earlier versions of JavaScript. This meant common problems would go undiscovered in regular expressions.
With TypeScript 5.5, TypeScript will now infer that a function returns a type predicate under certain conditions. And with control flow narrowing for constant indexed accesses, TypeScript now is able to narrow expressions in for obj[key]
when both obj
and key
are effectively constant.
TypeScript 5.5 makes API consumption of ECMAScript modules easier. Previously, if a developer was writing an ECMAScript module in Node.js, named imports were not available from the typescript
package. This has been fixed. TypeScript also now supports a new @import
comment tag that has the same syntax as ECMAScript imports.
TypeScript 5.5 also adds a transpileDeclaration
API, which is designed to generate a single declaration file based on input source text. The API is similar to transpileModule
for compiling a single file of TypeScript code.
TypeScript 5.5 follows TypeScript 5.4, which became generally available in March and brought preserved narrowing within function closures.
Copyright © 2024 IDG Communications, Inc.