Microsoft has announced the beta release of TypeScript 4.7. The key features of the latest version of the open-source programming language include:
- ECMAScript Module Support in Node.js: The researchers had been struggling for years to implement module support in Node.js. TypeScript 4.7 ends this struggle as it adds this functionality with two new module settings: node12 and nodenext.
- Control over Module Detection: TypeScript 4.7 introduces a new option called ‘moduleDetection’ for Javascript code.
- Control-Flow Analysis for Computed Properties: TypeScript 4.7 now analyses the type of computed properties and narrows them correctly. The new version knows that obj[key] is a string. Meaning, TypeScript can correctly check that computed properties are initialised by the end of a constructor body.
- Instantiation Expressions: TypeScript 4.7 can now take functions and constructors and feed them type arguments directly. With this, you can specialise makeBox to accept more specific types and reject anything else. This logic also works for constructor functions such as Array, Map, and Set.
- Optional Variance Annotations for Type Parameters: In this version, variance on type parameters can be explicitly specified.
- Resolution Customization with moduleSuffixes: TypeScript 4.7 now supports a moduleSuffixes option to customise how module specifiers are looked up. This feature can be useful for React Native projects where each target platform can use a separate tsconfig.json with differing moduleSuffixes.
- Resolution-mode: TypeScript now allows /// <reference types=”…” /> directives and import type statements to specify a resolution strategy.
- Groups-Aware Organize Imports: TypeScript has an Organize Imports editor feature for both JavaScript and TypeScript.
In the coming weeks, the TypeScript team will be polishing version 4.7 to get it ready for a Release Candidate.