Question presented to candidate:
"TypeScript 5.0 added const type parameters, as in function f<const T>(x: T). What do they do, and why would a library author use them instead of asking callers to write as const?"
What a strong answer should cover:
<const T>makes tsc inferTas if the argument literal had been writtenas const: literal types, readonly properties and readonly tuples, all the way down- The benefit: the precision is decided once by the function author, not remembered by every caller; the call site stays clean
- Limits: it only affects literals written in the call (a variable that was already widened stays widened), an explicit type argument turns it off, and the result is readonly
- Constraints matter: use
readonly unknown[]-style array constraints; with a mutable array constraint, 5.0 fell back to the constraint, and 5.3 relaxed that (on 5.4.5 the result is a mutable tuple) - Allowed on type parameters of functions, methods and classes, not interfaces or type aliases (error TS1277); it is erased at run time and freezes nothing
Code / implementation expected: Yes β a small defineOptions or defineRoutes helper written with and without const, with Equal checks of the inferred type.