TypeScript Utility Types
NoInfer<T> — control inference candidates
NoInfer blocks inference into its wrapped position while otherwise preserving the type relationship. It lets one argument determine a generic type and another be checked against that result without broadening it through inference. It does not forbid explicit type arguments, change runtime values or guarantee narrower inference in every surrounding signature. Example output: "red". Verified with strict TypeScript 5.8.3, ES2022 and Node.js 22.16.0. This utility affects static typing; no runtime validation or transformation is supplied by the type itself.
Formal Syntax & Structure
typescript syntaxtypescript
NoInfer<T>Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| T | type parameter | Type to check without using that occurrence as an inference source. |
Working Example
Example Snippettypescript
function choose<C extends string>(choices: readonly C[], fallback: NoInfer<C>): C { return choices[0] ?? fallback;}const result = choose(["red", "blue"], "blue");console.log(result);