ESM Support Has Been Added To TypeScript 4.7 In Node.js

The latest version of Microsoft’s strongly typed JavaScript, which is currently in beta, adds support for ECMAScript modules in Node.js.

TypeScript 4.7, which is now in beta, adds ECMAScript module (ESM) support for Node.js 12 as well as a slew of other coding improvements.

TypeScript 4.7, which was announced on April 8, is the latest version of Microsoft’s strongly typed JavaScript. ECMAScript module support in Node.js 12 is included in TypeScript 4.7, which was originally scheduled for TypeScript 4.5 late last year but was postponed.

Also on InfoWorld: Builder CEO: Where JavaScript is headed is super interesting ]

In the TypeScript 4.5 period, Node.js added nightly-only support for ECMAScript modules. These modules allow code to be packaged and reused. Because Node.js was based on a separate module system, CommonJS, it was difficult to implement this capability. With two moduleoptions, node12and nodenext, TypeScript 4.7 offers this functionality. This capability is looking for feedback, which may be provided on GitHub.

On May 10, TypeScript 4.7 will be released as a release candidate, followed by a final version on May 24. NPM can be used to access the beta:

npm install typescript@beta

TypeScript 4.7 also has the following features:

  • TypeScript 4.7 adds the moduleDetection option to control module detection.
  • To modify the lookup of module specifiers, the moduleSuffixesoption is available.
  • TypeScript evaluates the type of calculated attributes and narrows them correctly using control flow analysis for computer properties.
  • TypeScript may now infer more granularly from functions that use objects and arrays. This allows the types of these functions to flow in a consistent left-to-right direction, exactly like ordinary arguments.
  • Type parameters can be passed directly to functions and constructors.
  • Developers can provide variance on type parameters explicitly.
  • typeof queries can be performed on private fields.
  • Imports are organized in a group-aware manner.
  • For object literal methods, snippet completions are available.
  • 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 {} and object. This is a breaking change.
  • The lengthproperty of a readonlytuple is now readonly. This also is a breaking change.

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories