function routes<const T extends readonly string[]>(paths: T) {
return paths;
}
const r = routes(["/", "/about"]);
readonly ["/", "/about"]The answer is readonly ["/", "/about"]. A const type parameter (added in TypeScript 5.0) infers the argument as if you wrote it with as const. So the literal tuple, with its exact strings, is kept.string[] is the tempting wrong answer. You would get string[] only without the const modifier.
Read more
- Generics (https://www.typescriptlang.org/docs/handbook/2/generics.html)typescriptlang.org