The beta release of TypeScript 4.2 is now available. There are a number of new features being added, and a number of breaking changes as well.
In this version, rest elements can be used in more ways than before. Previously, they were only allowed at the last position of a tuple type, but they can now occur anywhere within a tuple. There is a restriction that rest elements can’t be followed by another optional element or rest element.
The TypeScript 4.2 beta also features smarter internals. It now tracks how types were constructed and differentiates type aliases to instances of other aliases.
Another new feature is that template literal expressions now have template literate types. Template literal types were introduced in 4.1 as a way to model specific patterns of strings, but there was inconsistency between types and expressions. Now, template string expressions will always start with template literal types.
Other new features in 4.2 include:
- Stricter checks for the “in” operator
- Abstract construct signatures
- –explainFiles that show why certain files are included in a program
- Relaxed rules between optional properties and string index signatures
- A new way to declare new functions and methods based on the call site
There are a number of breaking changes as well, such as template literal expressions now having template literal types, noImplicityAny errors apply to loose yield expressions, and more.
“We’re excited to hear your thoughts on TypeScript 4.2! With the beta we’re still in relatively early stages, but we’re counting on your feedback to help make this an excellent release. So try it today, and let us know if you run into anything,” Daniel Rosenwasser, program manager of TypeScript wrote in a post.