Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TypeScript · Type Alias

NoInfer

NoInfer<Type> blocks inference from the wrapped type while remaining identical to Type for other purposes. Use it when one generic argument should establish a type and another should only be checked against it.

Since
5.4

How it works

NoInfer<T> keeps TypeScript from using the wrapped type position as an inference source. The wrapped type otherwise behaves like T, so it still participates in checking after inference is determined elsewhere.

Syntax

NoInfer<Type>

Parameters

NameTypeDescription
TypetypeThe type to use while suppressing inference from the wrapped position.

Key points

  • NoInfer<T> prevents inference from the type argument position it wraps.
  • After inference, the wrapped type has the same type-checking meaning as the unwrapped type.
  • The utility became part of TypeScript in version 5.4.
  • Without an inference barrier, multiple function arguments can supply candidates for a generic type.
  • NoInfer stops TypeScript from searching inside the wrapped type for inference candidates.
  • A value rejected by the inferred union produces a normal assignability diagnostic at the call site.

Common mistakes

  • NoInfer does not create a different runtime or checking type; its special behavior is limited to inference.
  • Apply NoInfer at the position whose values should be validated against an inference established from another argument.

Example: Constrain a default value to inferred options

function createStreetLight<C extends string>(colors: C[], defaultColor?: NoInfer<C>) {
  return defaultColor;
}

const color = createStreetLight(["red", "yellow", "green"], "red");
console.log(color);

The first argument determines the allowed color union, while NoInfer prevents the optional default color from expanding that union.

When to use it

Validate defaults

A collection and a default value share a generic type, but only the collection should determine that type.

Control inference sources

Several arguments can contribute incompatible candidates to a generic type parameter.

Protect literal unions

An API should preserve a narrow inferred union instead of widening it from a later argument.

Interview questions

QWhat is NoInfer<T>?

NoInfer<T> is a utility type released in TypeScript 5.4. It blocks inference into T, while remaining identical to T for other type-checking purposes.

Follow-up: What problem does it solve in a generic function? It lets one argument establish the generic type and makes another argument conform to that established type instead of widening it.

QHow does NoInfer affect generic inference?

In a generic function with multiple candidate sources, TypeScript normally infers from values passed to those positions. Wrapping one position in NoInfer prevents that position from contributing inference candidates.

Follow-up: How would you use it for a default value? Infer the element union from the collection parameter, then write the default parameter as NoInfer<C>.

QWhy is NoInfer useful in the createStreetLight example?

For a street-light helper, C can be inferred from the colors array, while NoInfer<C> on defaultColor requires the default to belong to that inferred union. An invalid default therefore produces an assignability error.

Follow-up: What happens without NoInfer? The default argument may become an additional inference source, allowing an unintended value to influence C.

  • TypeScript 5.4
  • generic functions
  • type inference
  • utility types
  • createStreetLight

Source: Documentation - Utility Types - TypeScript. Checked 2026-10-15.