TypeScript 5.4 Released: NoInfer and Preserved Narrowing in Closures
TypeScript 5.4 added the NoInfer utility type, preserved type narrowing in closures after last assignments, and declarations for Object.groupBy.
Historical Archive. This article documents an event from 2024 and is preserved with its original date for reference. It is not current news, and details may have changed since publication.
What happened
TypeScript 5.4 was released on March 6, 2024, per Microsoft's official announcement. It is an incremental release that smooths out a few well-known rough edges in type inference and narrowing, while adding declarations for new JavaScript methods.
Preserved narrowing in closures
A common pain point was that a variable narrowed to a specific type would lose that narrowing inside a function closure. TypeScript 5.4 makes narrowing smarter: when a parameter or let variable is used in a non-hoisted function after its last assignment, the type-checker can safely keep the narrowed type inside that closure. In practice, code that reassigns a value to a more specific type and then uses it inside a callback now type-checks as developers expect.
The NoInfer utility type
TypeScript 5.4 introduced the NoInfer utility type. When calling a generic function, TypeScript infers type arguments from what you pass in, which is usually helpful but can produce an unwanted widening, for example accepting an invalid default value that was not in a provided list. Wrapping a type in NoInfer tells TypeScript not to use that position as a source for inference, so the compiler can correctly reject the invalid case. It replaces an awkward pattern of adding an extra type parameter.
New standard-library declarations
The release added declarations for JavaScript's new Object.groupBy and Map.groupBy static methods, which group the elements of an iterable into an object or map by a key function. It also added support for require() calls under certain module settings and checked import attributes, among other refinements.
Why it mattered
TypeScript 5.4's changes were mostly quiet quality-of-life improvements, but they addressed real friction: closures that lost narrowing and generic functions that inferred too eagerly were both frequent sources of confusion. Fixing them made everyday TypeScript feel more predictable without requiring developers to change how they write code.
Related on Skillo
See also: TypeScript 5.5's inferred type predicates.
Sources
Published date reflects the original event date (2024-03-06). This article is original Skillo editorial written from the sources above; facts were verified in September 2026.
Written by
Skillo Staff
0 Comments
Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.