TypeScript Generics and Advanced Type Operators

infer — capture a type within a conditional pattern

Within the extends pattern of a conditional type, infer introduces a type variable that can be used in the true branch. It extracts type information from a matching structure, such as a tuple element or function result. If the pattern does not match, the false branch applies. Inference from an overloaded function type uses its last signature rather than performing call-site overload resolution. Inferred variables are not runtime values. Example output: "ready". Local strict TypeScript 5.8.3 / ES2022 baseline. The type construct itself is erased; the logged value illustrates a checked use, not runtime type validation.

Formal Syntax & Structure

typescript syntaxtypescript
type Item<T> = T extends readonly (infer E)[] ? E : never;

Working Example

Example Snippettypescript
type Item<T> = T extends readonly (infer E)[] ? E : never;const value: Item<readonly ["draft", "ready"]> = "ready";console.log(value);
TypeScript Reference