TypeScript 4.5, a planned upgrade to Microsoft’s strongly typed language based on JavaScript, is set to support ECMAScript modules in Node.js.
TypeScript 4.5 became available as a beta release on October 1. Node.js, which can work with TypeScript, has been working to support ECMAScript modules (ESM), which enable packaging of JavaScript code for reuse. This work has been difficult because Node.js was built on a different module system, CommonJS, Microsoft said. But ESM was largely implemented in Node.js 12. With ESM support in mind, TypeScript 4.5 offers two new module
settings, node12
and nodenext
.
TypeScript 4.5 is due to reach the release candidate stage on November 2 and to be generally available on November 16. The beta is accessible via NuGet or NPM: npm install typescript@betacode
.
Also new in TypeScript 4.5:
lib
to better support the lib
setting from node_modules
.realpathSync
function is now leveraged on all operating systems. Previously, it was limited to Linux. Now it has been adapted to OSes that are typically case-sensitve, like Windows and MacOS.Awaited
type, is introduced for modeling operations like await
in async
functions or the .then()
method on Promises
. Awaited
can be useful for modeling existing APIs.module
setting, es2022
, is supported, providing top-level await
, meaning developers can use await
outside of async
functions.type
modifier on individual named imports.TypeScript builds on JavaScript by adding syntax for static types. The previous TypeScript release, TypeScript 4.4, became generally available in August.