|TypeScript 4.2 Release Candidate Available|
|Written by Kay Ewbank|
|Wednesday, 24 February 2021|
Microsoft has announced the release candidate of TypeScript 4.2. The new version improves the handling of rest elements in tuple types, and supports smarter type alias preservation.
The improvements to rest element handling in tuple types means rest elements will be correctly handled no matter where they occur in a tuple. In previous releases, they had to be located in the last position of the tuple type. There are still some restrictions - you can't have another optional element or a second rest element after the rest element, and you can only have one rest element per tuple.
The next change of note improves type alias preservation. TypeScript uses heuristics to determening when and how to display type aliases, but these heuristics haven't always interpreted things correctly for complex uses because of the way TypeScript represents types internally. When creating a union type out of one or more union types, it will always normalize those types into a new flattened union type – but doing that loses information. The type-checker didn’t have a way to know where that string | number | boolean had come from.
In TypeScript 4.2, the internals have been improved so that more of the original structures of types are retained, meaning that types are handled better.
Other improvements include stricter checks for the 'in' operator to make sure you can't accidentally use a non-object type on the right side of the in operator. TypeScript 4.2 ensures this can be caught at design-time.
Another change is relaxed rules between optional properties and string index signatures. String index signatures are a way of typing dictionary-like objects, where you want to allow access with arbitrary keys. The problem is when strings aren't present. Previous versions of TypeScript treated optional object properties as unassignable to otherwise compatible index signatures, due to the presence of undefined. The new version allows an assignment such as this, but it doesn't allow the assignment of non-optional properties with undefined in their types, nor does it allow writing undefined to a specific key.
or email your comment to: firstname.lastname@example.org
|Last Updated ( Wednesday, 24 February 2021 )|