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.

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

Also, in TypeScript 4.4, the “unknown” type will be the default for catching variables. According to Microsoft, in JavaScript, any type of value can be thrown and then caught in a catch clause, and in the past, TypeScript typed catch clause variables as “any,” but 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 being 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 make use of it.

TypeScript 4.4 also added support for static blocks in classes, which is an upcoming ECMAScript feature. Static blocks can be used to write a sequence of statements with their own scope that are able to 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 have to worry about leakage of variables.

The ‘–help’ option has also been updated in this release with changes to descriptions of compiler options and updated colours and other visual separation.

More information about the release is available here.

Tags: , , , , , , , , , , , , , , , , , , , , , ,
Nikoleta Yanakieva Editor at DevStyleR International