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.
TypeScript, a superset of JavaScript, introduces types to describe the shape of an object. It offers JavaScript developers an 'erasable type system' that removes all the types at compile time and returns it to JavaScript for run time. It's become a popular language for building apps for the browser.
TypeScript 4.1 introduces the template literal string type, which uses the same syntax as JavaScript's template literal strings but used in type positions.
SEE: Virtual hiring tips for job seekers and recruiters (free PDF) (TechRepublic)
"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 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.
TypeScript 4.1 also supports Facebook's new React 17 JavaScript library's factory functions jsx and jsxs via two new options for the jsx compiler options, react-jsx and react-jsxdev.
SEE: Microsoft's TypeScript 4.0 programming language arrives: It's a big milestone
Finally, the JSDoc tag @see now has better support in code editors like VS Code for TypeScript and JavaScript.
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.