ESM support for Node.js 16 was a late addition to the release. The TypeScript 4.7 beta introduced April 8 included ESM support for Node.js 12, which had been planned for TypeScript 4.5 late last year but was delayed.
However, because Node.js 12 is no longer supported, TypeScript’s builders started the stable target at Node.js 16, which provides newer ECMAScript module functionality such as pattern trailers while also defaulting TypeScript to a higher target that supports top-level
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 can be downloaded via NuGet or NPM:
npm install -D typescript
Other capabilities in TypeScript 4.7 include the following:
- Control flow analysis for bracketed element access now narrows the types of element accesses when the indexed keys are literal types and unique symbols
- To control module detection, TypeScript 4.7 introduces the option
moduleSuffixesoption is supported to customize lookup of module specifiers.
- 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.
- Organize Imports is performed in a group-aware manner.
- Snippet completions are provided for object literal methods.
readonlytuple now will treat its
readonly. This is a breaking change.
- A preview editor command is featured for Go to Source Definition.
- In another breaking change, when writing a
…spreadin JSX, TypeScript now enforces stricter checks that the given type is actually an object. As a result, values with the types
never, and, more rarely,
undefined, no longer can be spread into JSX elements.
Following the beta, TypeScript’s builders found that a
typeof capability on
#private fields, which had been planned for the release, had issues with API compatibility. The team also began doubting whether
typeof this.#somePrivate composes well on declaration emit. As a result, this capability has been left out of TypeScript 4.7.
A release candidate for TypeScript 4.7 was published on May 11. The previous version, TypeScript 4.6, which brought capabilities such as ECMAScript 2022 support and recursion checks, was published February 28.
Copyright © 2022 IDG Communications, Inc.