Skip to content

Generated enum type for routeId #6167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Conduitry opened this issue Aug 22, 2022 · 2 comments
Open

Generated enum type for routeId #6167

Conduitry opened this issue Aug 22, 2022 · 2 comments
Labels
feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. types / typescript
Milestone

Comments

@Conduitry
Copy link
Member

Describe the problem

$page.routeId is just a string currently, which means you can have typos that won't match the ID of any route. It would be nice if this were typed, so that typos will be caught as type errors, and so that any renamed pages or moved routes will also result in type errors if their corresponding $page.routeIds aren't also updated.

Describe the proposed solution

We know the route manifest at build time. We should be able to construct a 'foo' | 'bar' | 'baz' type that the routeId would adhere to. The question would be where this generated type ought to live and how it ought to be accessed by the app code. Ideally, people could just keep using the ambient $app/stores types, and these would pull in the appropriate enum from .svelte-kit.

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

@dummdidumm dummdidumm added feature / enhancement New feature or request types / typescript p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. labels Aug 22, 2022
@benmccann
Copy link
Member

One thing to think about when deciding whether/how to implement this - if we added the ability to import routes from another project I'm not quite as sure how to support that

@minht11
Copy link

minht11 commented Mar 29, 2025

Currently RouteId and LayoutIds have generated types, but are not exported
Image
you can access it somewhat with type RouteId = LayoutLoadEvent['route']['id'] would exporting it directly be possible?

In my case I am using route id to have different view transitions on different routes, I changed routes names but forgot to change route ids, having explicit types would have caught that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. types / typescript
Projects
None yet
Development

No branches or pull requests

5 participants