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.
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
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.
typeofqueries can be performed on private fields.
- Imports are organized in a group-aware manner.
- For object literal methods, snippet completions are available.
strictNullChecks, the type checker disables a type safety hole that was maintained for backward compatibility, where type parameters were considered to be assignable to
object. This is a breaking change.
lengthproperty of a
readonlytuple is now
readonly. This also is a breaking change.