TypeScript 4.4 Beta Is Now Available

TypeScript 4.4 brings Control-Flow Analysis of Aliased Conditions, and Symbol and Template String Pattern Index Signatures.

Recently, Microsoft announced the beta release of TypeScript 4.4.

Key highlights of the release include:

  • Control Flow Analysis of Aliased Conditions,  
  • Defaulting to the unknown Type in Catch Variables (--useUnknownInCatchVariables),
  • Symbol and Template String Pattern Index Signatures,
  • Exact Optional Property Types (--exactOptionalPropertyTypes),
  • tsc --help Updates and Improvements, and Spelling Suggestions for JavaScript.

In version 4.4 when TypeScript sees that you are testing a constant value, it does a little bit of extra work to see if it contains a type guard. If that type guard operates on a const, a readonly property, or an un-modified parameter, then TypeScript 4.4 is able to narrow that value appropriately. Different sorts of type guard conditions are preserved, not just typeof checks.

Control Flow Analysis of Aliased Conditions works transitively. So, if you have a constant assigned to a condition that has more constants in it, and those constants are each assigned type guards, then TypeScript can propagate the conditions later on.

Source: Microsoft

TypeScript 4.4 also addresses the limitations index signatures, and allows the feature for symbols and template string patterns. Index signatures now permit union types as well, as long as they’re a union of infinite-domain primitive types – specifically: string, number, symbol, template string patterns (e.g. `hello-${string}`).

TypeScript 4.4 is introducing a new flag called --useUnknownInCatchVariables, which changes the default type of catch clause variables from any to unknown. useUnknownInCatchVariables is enabled under the --strict family of options. So if you check your code using --strict, this option will automatically be turned on. 

In TypeScript 4.4, a new flag --exactOptionalPropertyTypes sets out that optional property types should be interpreted exactly as written. This flag is not part of the --strict family and needs to be turned on explicitly if you need this behavior.

4.4 brings performance improvements like Faster Declaration Emit, Faster Path Normalization, Faster Path Mapping, Faster Incremental Builds with --strict, Faster Source Map Generation for Big Outputs, and Faster --force Builds.

TypeScript 4.4 can cache whether internal symbols are accessible in different contexts, along with how specific types should be printed. These changes enhance TypeScript’s performance in code with fairly complex types, and is especially observed when emitting .d.ts files under the --declaration flag.

TypeScript often does several types of “normalization” on file paths in order to get them into a consistent format that the compiler can use everywhere. This include things like replacing backslashes with slashes, or deleteing intermediate /./ and /../ segments of paths. When TypeScript has to operates over millions of these paths, these operations end up being a bit slow. Starting with TypeScript 4.4, paths first undergo quick checks to see whether they need any normalization in the first place. These enhancements together reduce project load time by up to 10% on bigger projects, and notably more in massive projects.

With 4.4 is TypeScript is also experimenting with editor support for inlay text which can help display useful information like parameter names inline in your code. 

For additional details, you can visit the official announcement here.