What's new in TypeScript 4.7 Beta

TypeScript 4.7 Beta was just released and it is jam packed with new features and changes. Today we are going to talk about a few of those which I think are noteworthy and give you the information you need to get your hands on this Beta TypeScript release.

ECMAScript Module Support in Node.js

ECMAScript is a JavaScript standard meant to ensure the interoperability of web pages across different web browsers. Node.js is built on a very different module called CommonJS, this has made ECMAScript support a very difficult feature to implement. A few releases back experimental support was added in nightly builds to gather feedback from users. Now TypeScript 4.7 adds two modules to support this functionality, node12 and nodenext.

{
    "compilerOptions": {
        "module": "nodenext",
    }
}

CommonJS Interop

Now you can import CommonJS modules as if they were ES modules with a default export. Node.js may also synthesize named exports from CommonJS modules 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 with more granularity from functions contained within objects and arrays. This allows the types of these functions to flow consistently from left to right, exactly like ordinary arguments. You can see this in action below in this screenshot courtesy of Daniel Rosenwasser Senior Program Manager, TypeScript.

Improved-Function-Inference-in-Objects-and-Methods

We just scratched the surface of what was announced for TypeScript 4.7 Beta. There is quite a list of new features and changes with this Beta release soon to become Release Candidate. You can read all about them here. Drop us a comment below with what you're most excited about!

To get started using this release 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:

Older

What's new with the latest release of .NET Community Toolkit

Surface Laptop Go 2 reportedly coming soon

Newer