TypeScript 4.1 arrives with template literal types

The template literal type has the same syntax as template literal strings in JavaScript except it is used in type positions

TypeScript 4.1, an upgrade to Microsoft’s popular open source language that adds types to JavaScript, is now available as a production release. The upgrade features template literal types and a multitude of other improvements.

The template literal type has the same syntax as template literal strings in JavaScript except it is used in type positions. When used with concrete literal types, a new string literal type is produced by concatenating the contents.

In addition to introducing template literal types, TypeScript 4.1 lets developers re-map keys in mapped types with a new as clause. This new clause lets developers leverage features like template literal types to create new property names based on old ones. Keys can be filtered by producing never, saving developers from having to use an extra Omit helper type in some cases.

TypeScript 4.0, the current major release, arrived in August. Other capabilities in TypeScript 4.1 include:

TypeScript 4.1 can be accessed through NuGet or NPM:

npm install typescript

Related:

Copyright © 2020 IDG Communications, Inc.