On this page
  1. NoInfer
  2. Syntax & Overview
  3. Notes & Pitfalls
  4. Example

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

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