What are const type parameters in TypeScript 5.0?

Why Interviewers Ask This

Advanced questions like this reveal whether a candidate has internalized TypeScript deeply enough to make architectural decisions. Strong answers demonstrate both breadth and depth of experience.

Answer

Const type parameters (TypeScript 5.0) allow you to mark a generic type parameter with const, causing TypeScript to infer the narrowest (most specific) type for that parameter — equivalent to adding as const to the passed argument. Without const: function identity<T>(value: T): T { return value; } const result = identity(["a", "b"]); — T is inferred as string[], result type is string[]. With const: function identity<const T>(value: T): T { return value; } const result = identity(["a", "b"]); — T is inferred as readonly ["a", "b"], the narrowest possible type. This is particularly useful for functions that work with literal values and need to preserve the exact type without requiring callers to add as const everywhere. Common use case: type-safe routing, event systems, or any API where the literal type of arguments matters for the return type's correctness.

Common Mistake

Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your TypeScript experience.