Microsoft’s open-source TypeScript team has issued the first beta of TypeScript 4.1, bringing new features, new checking flags, and editor productivity improvements.
“String literal types in TypeScript allow us to model functions and APIs that expect a set of specific strings, explains Daniel Rosenwasser, a program manager on the TypeScript team.
“This is pretty nice because string literal types can basically spell-check our string values.”
The template also acts as a building block for building other string literal types.
The beta also brings key remapping in mapped types, allowing users to remap keys in mapped types with a new ‘as’ clause so they can use template literal types to create property names based on old ones.
TypeScript 4.1 allows for recursive conditional types too. Now conditional types can reference themselves within their branches, making it easier to write recursive type aliases.
Rosenwasser notes recursive types are powerful, but should be used sparingly because they can be computationally intensive and can lead to compile-time errors.
Users can access the beta on NuGet, or use npm to install it.
At the release of TypeScript 4.0 in August, Typescript’s co-creator Anders Hejlsberg told ZDNet that the main changes in TypeScript over the past two years have focused on improving the experience with editors like Microsoft’s VS Code, better error messages and better refactoring.