TypeScript version 4.7

TypeScript version 4.7

The TypeScript 4.7 version is released on the 24th of May 🎉.

Microsoft has released TypeScript 4.7, which addresses a very challenging feature -- ECMAScript Module Support in Node.js.

If you are not yet acquainted with TypeScript, it is a language that extends JavaScript by adding syntax for types. If you are not yet familiar with TypeScript, you can learn more about it here. The sorts of values you're dealing with and the kinds of functions you're calling may both be described with the assistance of types. This information may be used by TypeScript to assist you in avoiding common errors such as typos, missing arguments, and failing to remember to check for null and undefined. But type-checking isn't the only thing that TypeScript does; it also leverages the information from these types to provide you a fantastic authoring experience by enabling things like code completions, go-to-definition navigation, and renaming, among other features.

How to use TypeScript 4.7

You may start using TypeScript by downloading it from NuGet, or you can use npm in conjunction with the following command to install it:

npm install -D typescript

What's new in TypeScript 4.7

Here’s a list of what’s new in TypeScript 4.7:

  • ECMAScript Module Support in Node.js
  • Control over Module Detection
  • Control-Flow Analysis for Bracketed Element Access
  • Improved Function Inference in Objects and Methods
  • Instantiation Expressions
  • extends Constraints on infer Type Variables
  • Optional Variance Annotations for Type Parameters
  • Resolution Customization with moduleSuffixes
  • resolution-mode
  • Go to Source Definition
  • Groups-Aware Organize Imports
  • Object Method Snippet Completions

The team's emphasis is on support for ES Modules on Node which is a long-awaited feature among developers. This was an experimental feature on the TypeScript 4.5 version but finally, the Node integration has been made as stable in this new version.

Node.js's module architecture is built on top of CommonJS. The need for ECMAScript modules has risen as more and more apps become polymorphic. These have been supported by Node.js for the last several years. The ES Modules have been extensively supported since Node 12's release.

TypeScript 4.7 adds node12 and nodenext module settings. They can be used in the package.json via a new Node.js option called type that allows developers to define module or commonjs to control if JS files are read as either ES modules or CommonJS modules, with the default being CommonJS.

TypeScript 4.7 provides a moduleSuffixes option for customizing how module specifiers are resolved.

TypeScript 4.7 supports typeof queries against private fields.

TypeScript 4.7 is now capable of performing more grained inferences from functions contained inside objects and arrays. This enables the types of these functions to flow uniformly from left to right, as with simple arguments.

You can read more details from the official website


In conclusion, this is excellent! The support for ESM modules in Node was a challenge, and it's nice to see it in action. That doesn't mean there aren't any other reasons to favor this release.

✋If you have any questions about this article, ask them in our GitHub Discussions 👈 community. You can also Gitter

❤️ Like our page and subscribe to our feed for updates!