[✨] Type Safety for useNavigate Function #153
barel-mishal
started this conversation in
Proposals For Qwik
Replies: 1 comment
-
|
We moved this issue to |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem?
Hello Qwik community,
I've been using Qwik in my project and I'm finding it very useful, especially the
useNavigatefunction. It allows me to efficiently navigate through my site, rendering only the parts that change.However, I've noticed that the current implementation does not support type checking for the routes. As a TypeScript user, I find type checking to be a crucial part of my development process, as it catches potential errors early and improves the overall developer experience.
Describe the solution you'd like
I believe that having type-safe routes could be a significant improvement to the framework. For example, a possible implementation could involve defining a type that includes all possible routes in the application. Then, the
useNavigatefunction could accept this type, enforcing type safety at the component level and ensuring that only valid routes can be passed in.Describe alternatives you've considered
Route Enumeration: One other possibility is to define an enumeration (enum) of all your routes. This would allow you to use the enum as the type for the useNavigate function, providing compile-time checks for the route names. The downside is that it could be a bit cumbersome to maintain as your application grows and the number of routes increases.
Additional context
I wanted to ask if there's any ongoing work related to this or if there's interest in the community for this kind of feature? And, of course, I'm interested in contributing to this effort if it aligns with the goals of the framework.
Thank you for your time and looking forward to hearing your thoughts on this.
Best regards,
Barel Mishal
Beta Was this translation helpful? Give feedback.
All reactions