TypeScript 4.2 Beta Released

TypeScript has released the version 4.2 in Beta, which enables you to place rest elements anywhere within a tuple.

Recently, Microsoft announced the availability of TypeScript 4.2 Beta. The new release adds a number of new features and improvements to TypeScript.

New features in 4.2 include Leading/Middle Rest Elements in Tuple Types, Smarter Type Alias Preservation, Template Literal Expressions with Template Literal Types, Stricter Checks for the in Operator, --explainFiles, and more.

You can get 4.2 Beta through NuGet, or using npm with the command:  npm install typescript@beta

Earlier, TypeScript only allowed ...rest elements at the very last position of a tuple type. Starting with 4.2, rest elements can be placed anywhere within a tuple, with only a few restrictions. A rest element can occur anywhere in a tuple, so long as it’s not followed by another optional element or rest element.  You can use these non-trailing rest elements to model functions that take any number of leading arguments, followed by a few fixed ones.

In TypeScript 4.2 you can keep track of how types were constructed by keeping around parts of their original structures, before you normalize them.  4.2 also keep track of, and differentiate, type aliases to instances of other aliases. Now, being able to print back the types based on how you used them in your code means that you can avoid some unfortunately humongous types getting displayed, giving better .d.ts file output, error messages, and in-editor type displays in quick info and signature help.

Starting with 4.2, template string expressions now always start out with template literal types. And very similar to string literal types, these types disappear and turn into string via a process called widening if you assign one of these values to a mutable variable.

Other highlights of TypeScript 4.2 include –explainFiles, that show why certain files are included in a program; Relaxed rules between optional properties and string index signatures, and a new way to declare new functions and methods based on the call site.

For additional details, you can visit the official announcement here.



Next Recommended Reading Microsoft Announces TypeScript 4.2 RC