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.
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
- 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
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.
Related postsKotlin 1.7.0 Beta Enables Definitely Non-nullable Types AlmaLinux 9 is released TypeScript version 4.7 Angular 14 release