← All tips

TypeScript: `as const` for route maps

typescriptpatterns

Create strongly typed route strings.

const routes = { home: '/', search: '/search' } as const;
type Route = (typeof routes)[keyof typeof routes];