TypeScript 4.2 Is Out

The official release of TypeScript 4.2 is now available, featuring Smarter Type Alias Preservation, Leading/Middle Rest Elements in Tuple Types, Stricter Checks For The in Operator,--noPropertyAccessFromIndexSignature, The --explainFiles Flag, abstract Construct Signatures, and more.

Microsoft announced the official release of TypeScript 4.2

TypeScript,is an extension to JavaScript that adds static types and type-checking. TypeScript type-checker enables you to catch lots of common mistakes like typos, forgetting to handle null and undefined, and more.

TypeScript 4.2 features Smarter Type Alias Preservation, Leading/Middle Rest Elements in Tuple Types, Stricter Checks For The in Operator,--noPropertyAccessFromIndexSignature, The --explainFiles Flag, abstract Construct Signatures, and more.

Source: TypeScript

TypeScript 4.2 keep track of how types were constructed by keeping around parts of how they were originally written and constructed over time. Ability to print back the types based on how you used them in your code means that as a TypeScript user, you can now easily avoid some unfortunately humongous types getting displayed. This makes TypeScript a little bit more approachable for newcomers.

In 4.2, rest elements have been expanded in how they can be used. In earlier versions, TypeScript only allowed ...rest elements at the very last position of a tuple type. Now rest elements can occur anywhere within a tuple, with only a few restrictions. A rest element can now be placed anywhere in a tuple as long as it is not followed by another optional element or rest element.

In JavaScript, if you use a non-object type on the right side of the in operator, you get a runtime error. In 4.2 you can caught this at design-time.

4.2 introduces a new flag called --noPropertyAccessFromIndexSignature. Under this mode, users will be opted in to TypeScript’s older behavior that issues an error. 

4.2 also enables you to specify an abstract modifier on constructor signatures. abstract modifier added to a construct signature signals that you can pass in abstract constructors.  It really just signals that there is no intent to run the constructor directly, so it is safe to pass in either class type. You can now write mixin factories in a way that supports abstract classes.

Other new features in 4.2 include --explainFiles, Improved Uncalled Function Checks in Logical Expressions, Destructured Variables Can Be Explicitly Marked as Unused, and Relaxed Rules Between Optional Properties and String Index Signatures.

To learn more you can visit the official announcement here.



Next Recommended Reading Microsoft Announces TypeScript 4.2 RC