# `NoInfer<Type>`

> The `NoInfer<Type>` utility type in TypeScript blocks type inference from a specific position.

## What does NoInfer do in TypeScript?

The utility type that prevents TS from using a position as an inference candidate for a type parameter. Useful when one argument should only be checked against a type inferred from other arguments.

- Topic: Utility Types
- Type: utility type

## Example

Wrong:

```ts
function pick<T extends string>(options: T[], fallback: T) {
  return fallback;
}
pick(['sm', 'md'], 'xl');
```

Right:

```ts
function pick<T extends string>(options: T[], fallback: NoInfer<T>) {
  return fallback;
}
pick(['sm', 'md'], 'xl'); // error
```

`NoInfer` stops `fallback` from widening `T`, so 'xl' is rejected because it is not in the options list.

## Common mistakes

- A default value widens the generic to a union instead of being rejected as invalid.

## Key points

- `NoInfer` wraps only the parameters that should be checked against `T`, not the ones that define it.
- It replaces older tricks like an extra type parameter `U extends T` added only to block inference.

## Interview questions

### Does NoInfer change the type?

No, `NoInfer<T>` checks the same as `T`. It only stops that position from being used to infer `T`, and like all types it is erased at runtime.

### How was inference blocked before NoInfer?

With an extra type parameter such as `<T, U extends T>`, where `U` takes the argument. `NoInfer` replaces that trick.

## Related cards

- [Generic Types](https://wonderium.dev/ts/generic-types.md)
- [Generic Constraints](https://wonderium.dev/ts/generic-constraints.md)
- [const Type Parameters](https://wonderium.dev/ts/const-type-parameters.md)
- [Literal Types](https://wonderium.dev/ts/literal-types.md)

---

- Level: [TypeScript](https://wonderium.dev/ts.md)
- HTML version: https://wonderium.dev/ts/noinfer
- Last updated: 2026-11-25
