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. TypeScript is a superset of JavaScript that adds optional static types which can be checked by the TypeScript compiler to catch common errors in your programs. 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.
More InformationRelated ArticlesNew TypeScript Website Launched TypeScript 4.1 Adds Temporal Literal Types TypeScript 3.6 Generators Get Stricter TypeScript 3.5 Adds Smart Select TypeScript 3.2 Gets Stricter Checking TypeScript 3.1 Adds Mappable Tuples TypeScript 3.0 Adds Project References TypeScript Adds Unused Span Reporting TypeScript Adds Conditional Types More InformationRelated Articles
To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info |
|||
Last Updated ( Wednesday, 24 February 2021 ) |