Microsoft Ships TypeScript 4.6
Microsoft shipped TypeScript 4.6, listing these highlights:
- Allowing Code in Constructors Before
super(): TypeScript 4.6 is much more lenient in ensuring that
super() is called before referring to
this, no longer generating an error in certain circumstances while still ensuring that
super() occurs at the top-level before any references to
- Control Flow Analysis for Destructured Discriminated Unions: "When destructuring individual properties into a
const declaration, or when destructuring a parameter into variables that are never assigned to, TypeScript will check for if the destructured type is a discriminated union. If it is, TypeScript can now narrow the types of variables depending on checks of other variables So in our example, a check on
kind narrows the type of
- Improved Recursion Depth Checks: This has to do with comparing object types for compatibility in a structural type system that allows for generics, effectively cleaning up some false negatives that could be discernible by a human looking at the code.
- Indexed Access Inference Improvements: "TypeScript now can correctly infer to indexed access types which immediately index into a mapped object type."
- Control Flow Analysis for Dependent Parameters: TypeScript can now narrow parameters that depend on each other n cases where TypeScript infers the type of a function from a signature declared with a rest parameter whose type is a discriminated union of tuples.
--target es2022: "TypeScript's
--target option now supports
es2022. This means features like class fields now have a stable output target where they can be preserved. It also means that new built-in functionality like the
at() method on
Object.hasOwn, or the
cause option on
new Error can be used either with this new
--target setting, or with
- Removed Unnecessary Arguments in
react-jsx: This drops a
void 0 that is unnecessarily generated in certain scenarios, decreasing bundle sizes.
- JSDoc Name Suggestions: "TypeScript now provides suggestions for when parameter names don't match between your function and its JSDoc comment."
- TypeScript Trace Analyzer: A new tool provides a more readable view of the information provided by the
generateTrace flag that identifies types that are computationally expensive to create and compare against other types.
The Feb. 28 announcement fleshes out all of the above in much greater detail and and also details breaking changes.
Going forward, the TypeScript 4.7 Iteration Plan (pictured above) shows what's on tap for the next edition, due to debut on May 24.
David Ramel is an editor and writer for Converge360.