Microsoft simply introduced that TypeScript 5.4 is now obtainable. TypeScript is an extension to JavaScript that provides static sorts to the language, and it was created and is maintained by Microsoft.
TypeScript 5.4 introduces options just like the NoInfer utility sort, the power to protect sort refinements for closures that have been created previous the final task, and declarations for JavaScript’s Object.groupBy and Map.groupBy.
The NoInfer utility sort tells TypeScript to not attempt to match inside sorts to discover a candidate for sort inference. This was wanted as a result of usually, TypeScript tries to deduce sort arguments based mostly on what you’re passing in, however there are conditions the place you may not need it to make these assumptions.
In keeping with Microsoft, TypeScript may make assumptions based mostly on the examine you’ve carried out to find out a extra particular sort for a variable, however these new sorts weren’t at all times preserved in operate closures. On this newest launch, it now preserves “sort refinements for parameters, native let variables, and catch clause variables in closures which can be created previous the final task to these parameters or variables,” the PR says.
This launch additionally provides new declarations to go together with JavaScript’s new static strategies Object.groupBy and Map.groupBy. Object.groupBy is utilized in iterables and it makes use of a operate that determines the group that every ingredient of the iterable ought to be positioned in, after which makes a key for every group. It then makes use of the important thing to create an object by which the important thing maps to an array containing the unique ingredient. Map.groupBy is analogous, and produces a Map as an alternative of an object.
Different new options on this launch embrace:
- The power to make use of require() when setting module settings to protect, which is a newly obtainable possibility
- Checking import attributes and assertions towards the ImportAttribute sort
- A fast repair so as to add a brand new parameter to capabilities which can be known as with too many arguments
- Help for “subpath imports”
Microsoft additionally deprecated various choices in TypeScript 5.4, together with chatset, importsNotUsedAsValues, noImplicitUseStrict, and extra.