On this page
NoInfer
Prev: `Awaited` | Up: function_and_promise | Next: `ConstructorParameters`
Rel: function_and_promise, Conditional & Mapped Types
Ref: TypeScript Docs — Utility Types
Tags: #public #web #typescript #utility-types #function_and_promise #tier/standard
Syntax & Overview
NoInfer<T>
Blocks TypeScript from inferring a generic type parameter from a specific argument position (TS 5.4+).
Notes & Pitfalls
- Blocks inference from a specific parameter (TS 5.4+): Forces TypeScript to infer
Tfrom the primary source parameter and validate the secondary parameter against it.
Example
function pickDefault<T extends string>(options: readonly T[], fallback: NoInfer<T>): T {
return options[0] ?? fallback;
}
pickDefault(["light", "dark"], "dark"); // OK
// pickDefault(["light", "dark"], "blue"); // error: "blue" not in "light" | "dark"
Linked from
Related notes
- tuts/typescript/utility_types/function_and_promise/Awaited Linked here; links to this page; shared tags: #tier, #typescript, #web
- tuts/typescript/utility_types/function_and_promise/ConstructorParameters Linked here; links to this page; shared tags: #tier, #typescript, #web
- tuts/typescript/utility_types/function_and_promise Linked here; links to this page; shared tags: #typescript, #web
- tuts/typescript/type_system/conditional_and_mapped_types Linked here; shared tags: #typescript, #web
- tuts/typescript/type_system/generics_and_constraints links to this page; shared tags: #typescript, #web
- tuts/typescript/builtins/any shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/as_const shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/asserts shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/enum shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/infer shared tags: #tier, #typescript, #web