What are const type parameters in TypeScript 5.0?

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.