The TypeScript team announced the release of TypeScript 4.1, which includes powerful template literal types, key remapping of mapped types, and recursive conditional types.

Template literal types have a very enthusiastic response from the community. This new feature provides the ability to use normal string literal types as definitions for other types, making it easy to create and enforce your preferred template syntax grammar.

Template string literals can also get generated dynamically and infer from substitution positions within the template string. To further support common use cases in template string literals, TypeScript also adds new utility type aliases for modifying letter casing: Uppercase, Lowercase, Capitalize, and Uncapitalize.

The community has created many interesting template string literals examples, including querySelector, router parameter parsing, expression parsing, JSON parsing and serializing, GraphQL typed AST, SQL query validation, CSS parsing, games, spell checking, and more.

Haskell and PureScript have a similar feature and it is great to see support added to TypeScript.

TypeScript 4.1 also improves mapped types by adding key remapping. Mapped types were previously limited to new object types with their provided keys. Now mapped types support the creation of new keys or the filtering out of existing keys.

#typescript #javascript #web-development #programming #developer

TypeScript 4.1 Adds Template Literal Types
3.95 GEEK