# const Type Parameters

> The `const` modifier on type parameters in TypeScript infers the most specific literal types for generic arguments.

## What does the const modifier on a generic type parameter do in TypeScript?

The modifier on a generic type parameter that makes TS infer arguments as if they were written with `as const`. Literal values and readonly tuples are preserved instead of being widened to `string` or arrays.

- Topic: Advanced Types
- Type: concept

## Example

Wrong:

```ts
function routes<T extends string[]>(paths: T) {
  return paths;
}
const r = routes(['home', 'about']); // string[]
```

Right:

```ts
function routes<const T extends readonly string[]>(paths: T) {
  return paths;
}
const r = routes(['home', 'about']); // readonly ['home', 'about']
```

`const T` with a readonly constraint infers the exact tuple without callers writing `as const`.

## Common mistakes

- Passing a variable declared earlier and expecting literal types to be inferred.

## Key points

- Array constraints use `readonly unknown[]`, since a mutable constraint drops the literal tuple inference.
- Literals are written directly in the call, as `const` does not affect values from variables.
- `<const T>` replaces asking callers to add `as const` to every argument.

## Interview questions

### const type parameter vs as const: what is the difference?

`as const` is written by each caller. `<const T>` is written once in the function and applies to every literal argument.

### Does a const type parameter make the value readonly at runtime?

No, it only changes inference. Use `Object.freeze()` for runtime immutability.

## Related cards

- [as const](https://wonderium.dev/ts/as-const.md)
- [Generic Types](https://wonderium.dev/ts/generic-types.md)
- [Literal Types](https://wonderium.dev/ts/literal-types.md)
- [Generic Constraints](https://wonderium.dev/ts/generic-constraints.md)
- [`Readonly<T>`](https://wonderium.dev/ts/readonly.md)

---

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