Microsoft announced TypeScript 4.5 RC, which includes Nightly-Only ECMAScript Module Support in Node.js, support for ‘lib’ from ‘node_modules’, and more features.
The TypeScript 4.5 beta initially added new settings to support directly running ECMAScript modules in Node.js; however, Microsoft believes that the current experience needs more “bake time” before it can be used more broadly, according to Daniel Rosenwasser, a senior program manager at TypeScript in a blog post.
Also, to ensure that TypeScript and JavaScript support works well out of the box, TypeScript bundles a series of declaration files (.d.ts files) that represent the available APIs in the JavaScript language, and the standard browser DOM APIs.
TypeScript 4.5 introduces a new utility type called the ‘Awaited’ type. This type is meant to model operations like ‘await’ in ‘async’ functions, or the ‘.then()’ method on ‘Promise’s – specifically, the way that they recursively unwrap ‘Promise’s.
Also, TypeScript 4.5 now can narrow values that have template string types, and also recognizes template string types as discriminants.
In addition, the new TypeScript version includes tail-recursion elimination on conditional types.
“TypeScript often needs to gracefully fail when it detects possibly infinite recursion, or any type expansions that can take a long time and affect your editor experience. As a result, TypeScript has heuristics to make sure it doesn’t go off the rails when trying to pick apart an infinitely-deep type, or working with types that generate a lot of intermediate results,” Rosenwasser added.
Other features include Template String Types as Discriminants, –module es2022, Disabling Import Elision, type Modifiers on Import Names, Private Field Presence Checks.
Additional details on all of the new features and changes in TypeScript 4.5 RC are available here.