![](/style/images/good.png)
![](/style/images/bad.png)
TypeScript 4.7 adds ESM support in Node.js
source link: https://www.infoworld.com/article/3656801/typescript-47-adds-esm-support-in-nodejs.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
TypeScript 4.7 adds ESM support in Node.js
Now in a beta release stage, the next version of Microsoft’s strongly typed JavaScript introduces support for ECMAScript modules in Node.js.
TypeScript 4.7, now in a beta release, offers ECMAScript module (ESM) support for Node.js 12 as well as a multitude of coding enhancements.
Unveiled April 8, TypeScript 4.7 is the latest planned version of Microsoft’s strongly typed JavaScript. TypeScript 4.7 backs ECMAScript module support in Node.js 12, something that had been planned for TypeScript 4.5 late last year but was delayed.
[ Also on InfoWorld: Builder CEO: Where JavaScript is headed is super interesting ]
Nightly-only support for ECMAScript modules in Node.js was rolled out in the TypeScript 4.5 timeframe. These modules enable reuse of code via packaging. Implementing this support has been difficult because Node.js was built on a different module system, CommonJS. TypeScript 4.7 adds this functionality with two module
settings, node12
and nodenext
. Feedback on this capability is sought and can be offered on GitHub.
TypeScript 4.7 is due to reach a release candidate stage on May 10, followed by a final release on May 24. The beta can be accessed via NPM:
npm install typescript@beta
Other capabilities in TypeScript 4.7 include:
- To control module detection, TypeScript 4.7 introduces the option
moduleDetectio
n. - A
moduleSuffixes
option is supported to customize lookup of module specifiers. - With control flow analysis for computer properties, TypeScript analyzes the type of computed properties and narrows them correctly.
- TypeScript now can perform more granular inferences from functions with objects and arrays. This allows types of these functions to consistently flow in a left-to-right manner, just like for plain arguments.
- Functions and constructors can be fed type arguments directly.
- Developers can explicitly specify variance on type parameters.
typeof
queries can be performed on private fields.- Organize Imports is performed in a group-aware manner.
- Snippet completions are provided for object literal methods.
- Under
strictNullChecks
, the type checker disables a type safety hole that was maintained for backward compatibility, where type parameters were considered to be assignable to{}
andobject
. This is a breaking change. - A
readonly
tuple now will treat itslength
property asreadonly
. This also is a breaking change.
Predecessor TypeScript 4.6, centering on capabilities such as ECMAScript 2022 support and recursion checks, was published February 28.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK