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.
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
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
moduleSuffixesoption 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.
typeofqueries can be performed on private fields.
- Organize Imports is performed in a group-aware manner.
- Snippet completions are provided for object literal methods.
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.
readonlytuple now will treat its
readonly. This also is a breaking change.
Paul Krill is an editor at large at InfoWorld, whose coverage focuses on application development.
Copyright © 2022 IDG Communications, Inc.