TypeScript 4.7 Beta has just been released and is packed full of new features and changes. Today we’re going to talk about a few that I think stand out and give you the information you need to get your hands on this TypeScript beta.
ECMAScript module support in Node.js
"compilerOptions": "module": "nodenext",
You can now import CommonJS modules as if they were ES modules with a default export. Node.js may also synthesize appointed exports from CommonJS mods in some circumstances.
// ./foo.cts export function helper() console.log("hello world!"); // ./bar.mts import helper from "./foo.cjs"; // prints "hello world!" helper();
Improved function inference in objects and methods
TypeScript 4.7 can now infer functions contained in objects and arrays with more granularity. This allows the types of these functions to flow consistently from left to right, just like ordinary arguments. You can see it in action below in this screenshot courtesy of Daniel Rosenwasser Senior Program Manager, TypeScript.
We’ve just scratched the surface of what’s been announced for TypeScript 4.7 Beta. There is a whole list of new features and changes with this beta which will soon become a release candidate. You can read all about them here. Leave us a comment below with what excites you the most!
To start using this version, you can use the following npm command.
npm install [email protected]
For those using Visual Studio Code, you can get editor support by following the instructions here.
Share this post: