const type parameters keep literal types without as const
A function that takes an array of strings widens ["a", "b"] to string[] and loses the union. A const type parameter keeps the literals at the call site.
function defineRoutes<const T extends readonly string[]>(routes: T) { return routes; }
const routes = defineRoutes(["/", "/blog"]); // readonly ["/", "/blog"]Since TypeScript 5.0. It is what as const did, moved into the signature so every caller gets it without remembering to.
typescript