Contents
The template literal type or “template literals” has the same syntax as string literal types in JavaScript, except that it is used in type positions.
Now available in production, the TypeScript 4.1 update to Microsoft’s open-source language adds types to JavaScript. This latest version is enriched with literal types of templates and brings a large number of other improvements.
The type literal of the template has the same syntax as the type literal strings in JavaScript, except that it is used in such positions. When used with concrete literal types, a new string literal type s is produced by the concatenation of contents.
In addition to adding the literal types of templates, TypeScript 4.1 allows developers to rearrange the keys in the mapped types with a new as a clause. This new clause allows developers to take advantage of features like literal types in templates to create new property names based on the old ones. Keys can be filtered by producing never, which eliminates the need for developers to use an additional Omit helper type in some cases.
TypeScript 4.0, the current major release, was released in August.
Other features
Other features of TypeScript 4.1 include :
– L was able to use conditional recursive types : some restrictions are eased for conditional types e t these can now be referenced immediately in their branches, which facilitates writing aliases recursive types. Microsoft specifies that recursive types should be used responsibly and sparingly.
– A new flag – noUncheckedIndexedAccess provides a node where every property access or indexed access is considered potentially undefined. This flag can detect out-of-range errors but can create noise in a large number of codes. It is not automatically enabled by the –strict flag.
– The paths option can be used without baseUrl , to avoid a problem created by bad paths used by auto-imports.
– checkJs now implies allowJs , correcting a situation where starting a verified JavaScript project required both allowJs and checkJs , which caused friction.
– The functions default jsx and jsxs the framework React 17 are supported by two new options to the s options react-jsx and react-jsxdev the compiler jsx .
– JSDoc @ see tag now offers better editor support for JavaScript and TypeScript .
– In a breaking change, members marked as abstract can no longer be marked as asynchronous. In another breakthrough change, the resolution settings are no longer optional in Promise.
TypeScript 4.1 is accessible via NuGet or via the NPM command : npm install typescript .
Paul Krill / IDG (adaptation Jean Elyan)
Discussion about this post