T
TanStack•13mo ago
flat-fuchsia

Routes with specific search params validator

How would I got about defining a type that accepts any of my routes, but with a specific search params valdidator? I use Zod for the validator if that matters.
15 Replies
ambitious-aqua
ambitious-aqua•13mo ago
are you just looking for types? or also runtime logic? how do you define a valid route?
flat-fuchsia
flat-fuchsiaOP•13mo ago
I just need a type that allows me to pass any route with a specific search param validator, so the Route objects that are exported by each route. So a valid route would be any routes in my app, that has the correct search param validator.
ambitious-aqua
ambitious-aqua•13mo ago
can you give me a more detailed example please? with a few valid routes and some input you want to validate against
flat-fuchsia
flat-fuchsiaOP•13mo ago
ambitious-aqua
ambitious-aqua•13mo ago
and what would you do that type? I just see that you want to check that a route has a specific search schema but what then?
flat-fuchsia
flat-fuchsiaOP•13mo ago
I need to use it as a function parameter
ambitious-aqua
ambitious-aqua•13mo ago
can you show a full example of all of that?
ambitious-aqua
ambitious-aqua•13mo ago
we generally recommend not importing the Route as it is very easy to create circular dependencies where typescript will bail out instead, we recommend using getRouteApi so what you would need is passing a routeId to a function and that should then validate the search type
flat-fuchsia
flat-fuchsiaOP•13mo ago
Okay, thank you very much!
ambitious-aqua
ambitious-aqua•13mo ago
but you would need a type for that I have built something like that it was not very efficient in terms of type performance ... I'll create an example for you later
flat-fuchsia
flat-fuchsiaOP•13mo ago
That would be much appreciated 😀
ambitious-aqua
ambitious-aqua•13mo ago
Manuel Schiller
StackBlitz
Router Quickstart File Based Example (forked) - StackBlitz
Run official live example code for Router Quickstart File Based, created by Tanstack on StackBlitz
ambitious-aqua
ambitious-aqua•13mo ago
Please be aware that this uses internal types that might change @Chris Horobin maybe this is another candidate for a type primitive?
flat-fuchsia
flat-fuchsiaOP•13mo ago
Thank you so much!

Did you find this page helpful?