Microsoft has announced the official release of TypeScript 4.2, the latest version of its JavaScript superset programming language.
There are a number of new features in this release, including smarter type alias preservation, leading/middle rest elements in tuple types, and stricter checks for the “in” operator.
Type aliases can be used to avoid having to repeat functions that work for a number of different types, such as strings, numbers, and booleans. An issue arises when TypeScript tries to normalize union types into a flattened union type, which results in information loss, thus forcing the type-checker to search for every combination of types to see what type aliases might have been used. This release improves the internals around type aliases to keep track of how types were constructed and enable types to be printed the way they were used in the code.
Another new change in TypeScript 4.2 is an expansion to how rest elements can be used. Previously they could only be used in the last position of a tuple type, but now they can be used anywhere within a tuple. The one exception is that it can’t be followed by another optional element or rest element.
TypeScript 4.2 also provides stricter checks for the “in” operator. Using a non-object type on the right side of the “in” operator throws a runtime error in JavaScript, so this change will help to ensure that these issues are caught during the development process.
Other new features in TypeScript 4.2 include –noPropertyAccessFromIndexSignature, abstract construct signatures, the –explainFiles flag, improved uncalled function checks in logical expressions, destructured variables that can be explicitly marked as unused, relaxed rules between optional properties and string index signatures, and the ability to declare new functions and methods based on the call-site.
The TypeScript team is also already working on version 4.3 and expects to release the first beta on March 30 and the final release on May 25.
The post TypeScript 4.2 comes with smarter type alias preservation appeared first on SD Times.
from SD Times https://ift.tt/37F0jdl
Comments
Post a Comment