A route registry can drive both lookup and allowed route names. Type the keys from the registry so a removed route cannot survive in a separate union.
Worked example
type Route = { path: string; method: "GET" | "POST" };
const routes = {
list: { path: "/jobs", method: "GET" },
create: { path: "/jobs", method: "POST" },
} as const satisfies Record<string, Route>;
console.log(((key: keyof typeof routes) => routes[key])("list"));Result
{ path: '/jobs', method: 'GET' }Implementation notes
A lookup accepts a string at runtime even when the public helper uses a restricted key type. Validate external route names before indexing.
Try it yourself
Rename a registry entry and check a caller using its previous name.
Open the TypeScript example →Editorial date November 11, 2026 · Published December 6, 2026