0

TypeScript 5.4 beta arrives

 7 months ago
source link: https://www.infoworld.com/article/3712660/typescript-54-beta-arrives.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

TypeScript 5.4 beta arrives

Latest update to the strongly-typed JavaScript preserves type refinements in closures following last assignment and introduces a NoInfer utility type.

By Paul Krill

Editor at Large,

InfoWorld | Jan 30, 2024 2:00 am PST

A pile of wooden letters.

Shaldark Illustrations/Shutterstock

TypeScript 5.4, a planned update to the strongly typed JavaScript variant from Microsoft, has reached beta availability. New capabilities include preserved narrowing within function closures created after the last assignment and a NoInfer type to block inferences to valid but unwanted types.

Released January 29, TypeScript 5.4 can be accessed via NuGet or NPM. In NPM, use the following command:

npm install -D typescript@beta

TypeScript 5.4 makes narrowing smarter. Detailing the improvement, Microsoft said a common pain point in TypeScript was that narrowed types were not always preserved within function closures. In TypeScript 5.4, when parameters and let variables are used in non-hoisted functions, the type checker will look for a last assignment point. If one is found, TypeScript can narrow from outside the containing function.

TypeScript 5.4 also introduces a NoInfer<T> utility type. Surrounding a type in NoInfer<…> gives a signal to TypeScript to match the inner types to find candidates for type inference. The utility type addresses an issue in which TypeScript can infer type arguments from whatever is passed in. But it is not always clear what is the best type to infer, leading TypeScript to reject valid calls and make other mistakes.

0 seconds of 30 secondsVolume 0%
This ad will end in 29

Other improvements in TypeScript 5.4:

  • Declarations are added for JavaScript’s new groupBy and Map.groupBy static methods. Object.groupBy takes an iterable and a function deciding which group each element should be placed in. The function must make a key for each distinct group, and Object.groupBy uses that key to make an object where every key maps to an array containing the original element. Map.groupBy is similar, but produces a Map rather than a plain object.
  • Support has been added for require( ) calls in --moduleResolution bundler and --module preserve.
  • Import attributes and assertions are now checked against the global ImportAttributes type. This means runtimes now can more accurately describe the import attributes.
  • A Quick Fix allows you to add a new parameter to functions called with too many arguments.
  • TypeScript now reduces intersections with type variables and primitives more aggressively, depending on how the type variable’s constraint overlaps with these primitives.
  • Deprecations have been added from TypeScript 5.0 such as target: ES3 code, NoImplcitUseStrict, charset, and out. TypeScript 5.4 likely will be the last version in which the list of deprecations continues to function as normal.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK