TypeScript 5.4 Adds NoInfer Type |
Written by Ian Elliot |
Tuesday, 12 March 2024 |
TypeScript 5.4 has been released, with the addition of a NoInfer utility type alongside preserved narrowing in closures following last assignments. TypeScript is a superset of JavaScript that adds optional static types which can be checked by the TypeScript compiler to catch common errors in your programs. TypeScript can use this information to help you avoid about mistakes like typos, missing arguments, or forgetting to check for null and undefined. The new NoInfer utility type solves a potential problem when calling generic functions. TypeScript tries to infer type arguments from whatever you pass in, but it's not always clear what the type would be best as the choice to infer. The new NoInfer<T> utility type can be used to signal to TypeScript not to try and match against the inner types to find candidates for type inference. The addition of preserved narrowing in closures following last assignments means that when TypeScript has worked out a more specific type for a variable based on checks that you perform (type narrowing), that type is preserved in function closures. The next improvement is the addition of declarations for JavaScript's new Object.groupBy and Map.groupBy static methods. Object.groupBy takes an iterable. It also takes a function that groups all the elements by making a key for each distinct group. Object.groupBy uses that key to make an object where every key maps to an array with the original element in it. Map.groupBy is similar, but produces a Map instead of a plain object. Other improvements in this version include TypeScript checking the import attributes and assertions against the ImportAttribute type; and better handling of functions that are called with too many arguments. TypeScript 5.4 is available now.
More InformationRelated ArticlesTypeScript 5 - Smaller, Simpler, Faster TypeScript 4.7 Adds Node.js ECMAScript Module Support TypeScript 4.6 Improves Constructors TypeScript 4.4 Improves Control Flow Analysis TypeScript 4.3 Adds Separate Property Write Types TypeScript 4.2 Release Candidate Available New TypeScript Website Launched TypeScript 4.1 Adds Temporal Literal Types To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info |
Last Updated ( Tuesday, 12 March 2024 ) |