Microsoft just announced that TypeScript 5.4 is now available. TypeScript is an extension to JavaScript that adds static types to the language, and it was created and is maintained by Microsoft.

TypeScript 5.4 introduces features like the NoInfer utility type, the ability to preserve type refinements for closures that were created past the last assignment, and declarations for JavaScript’s Object.groupBy and Map.groupBy. 

The NoInfer utility type tells TypeScript not to try to match inner types to find a candidate for type inference. This was needed because normally, TypeScript tries to infer type arguments based on what you are passing in, but there are situations where you might not want it to make those assumptions.

According to Microsoft, TypeScript can also make assumptions based on the check you’ve performed to determine a more specific type for a variable, but these new types weren’t always preserved in function closures. In this latest release, it now preserves “type refinements for parameters, local let variables, and catch clause variables in closures that are created past the last assignment to those parameters or variables,” the PR says

This release also adds new declarations to go with JavaScript’s new static methods Object.groupBy and Map.groupBy. Object.groupBy is used in iterables and it uses a function that determines the group that each element of the iterable should be placed in, and then makes a key for each group. It then uses the key to create an object in which the key maps to an array containing the original element. Map.groupBy is similar, and produces a Map instead of an object. 

Other new features in this release include:

  • The ability to use require() when setting module settings to preserve, which is a newly available option
  • Checking import attributes and assertions against the ImportAttribute type
  • A quick fix to add a new parameter to functions that are called with too many arguments
  • Support for “subpath imports”

Microsoft also deprecated a number of options in TypeScript 5.4, including chatset, importsNotUsedAsValues, noImplicitUseStrict, and more.