TypeScript 4.4 brings control flow analysis

by Joseph K. Clark

Microsoft has announced the general availability of TypeScript 4.4.  This latest release introduces control flow analysis for aliased conditions and discriminants, which checks to see if a type guard has been used before a particular piece of code. 

Another new feature is index signatures for symbol and template string patterns. Index signatures are used to describe properties that must use a specific type, but until now, they could only be used on string and number keys. 

flow analysis

Also, in TypeScript 4.4, the “unknown” type will be the default for catching variables. According to Microsoft, in JavaScript, any kind of value can be thrown and then seen in a catch clause, and in the past, TypeScript typed catch clause variables as “any.” Still, once it added the “unknown” type, it realized it was a better choice than “any” for catch clauses. This release introduces a new flag called –useUnknownInCatchVariables that changes the default type to “unknown” from “any.”

Another new flag introduced in TypeScript 4.4 is ‘–exactOptionalPropertyTypes,’ which specifies that property types be interpreted as written. According to Microsoft, this flag is not part of the –strict family and must be turned on if a developer wants to use it. 

TypeScript 4.4 also added support for static blocks in classes, which is an upcoming ECMAScript feature. Static blocks can write a sequence of statements with their own scope that can access private fields within a containing class. This allows developers to write more complex initialization code with the capabilities of writing statements, full access to a class’ internals, and not worry about leakage of variables. 

The ‘–help’ option has also been updated in this release with changes to descriptions of compiler options and updated colors, and other visual separation.  More information about the release is available here.

Related Posts

Leave a Comment