TypeScriptadvanced
const type parameters to preserve literal inference in generics
const asConstTuple = <const T extends readonly string[]>(...values: T): T => values;
export const statuses = asConstTuple("pending", "active", "done");
export type Status = (typeof statuses)[number];Stop a generic function from widening ['pending','active'] to string[] on the way in, without forcing every caller to write as const.