TypeScript 4.5 Release Candidate delays ECMAScript support

Microsoft has made available a Release Candidate (RC) for TypeScript 4.5, its programming language that builds on the capabilities of JavaScript. This release puts the ECMAScript module support for Node.js on hold, but Microsoft otherwise expects no further changes between this and the stable release of TypeScript 4.5 apart from critical bug fixes.

TypeScript 4.5 was expected to feature ECMAScript module support for Node.js 12, but this has now been deferred to a future release, although it will still be available as an experimental feature in nightly releases of the platform. Microsoft said it felt that the current support needed more “bake time” and it was better to smooth out the user experience instead of releasing something that would ultimately be too frustrating for many users.

What TypeScript 4.5 RC does add is a new utility type called the Awaited type, which is intended to be helpful for modelling existing APIs like await in async functions, as well including JavaScript built-ins like Promise.allPromise.race. This solves some problems around inference with Promise.all that would have failed in earlier releases, Microsoft said.

TypeScript 4.5 also introduces a way to override a specific built-in lib in a manner similar to how @types/support works. When deciding which lib files TypeScript should include, it will first look for a scoped @typescript/lib-* package. This allows developers to use the package manager to install a specific package to take over for a given lib, lock a project to a specific version of the DOM APIs, for example.

Another change is that TypeScript 4.5 performs some tail-recursion elimination on conditional types in order to avoid instances where code may cause infinite recursion.

TypeScript 4.5 now can also narrow values that have template string types, and recognises template string types as discriminants, according to Microsoft.

Other changes include faster project loading times through TypeScript using the realpathSync.native function in Node.js, and new snippet completions that add some default text and allow the sure to tab through bits and pieces of the code to adjust.

TypeScript 4.5 also now supports an ECMAScript proposal for import assertions. This is a syntax used by runtimes to make sure that an import has an expected format.

Microsoft warns that TypeScript 4.5 contains changes to its built-in declaration files which may affect compilation. Because Awaited is now used in lib.d.ts and as a result of await, developers may also see certain generic types change that might cause incompatibilities.

TypeScript also no longer allows types to be assignable to conditional types that use infer, or that are distributive. For full details of all the changes and how to get TypeScript 4.5 RC, see the post announcing it on the TypeScript blog.