T
TanStack•10mo ago
yappiest-sapphire

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
automatic-azure
automatic-azure•10mo ago
are you just looking for types? or also runtime logic? how do you define a valid route?
yappiest-sapphire
yappiest-sapphireOP•10mo 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.
automatic-azure
automatic-azure•10mo ago
can you give me a more detailed example please? with a few valid routes and some input you want to validate against
yappiest-sapphire
yappiest-sapphireOP•10mo ago
automatic-azure
automatic-azure•10mo 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?
yappiest-sapphire
yappiest-sapphireOP•10mo ago
I need to use it as a function parameter
automatic-azure
automatic-azure•10mo ago
can you show a full example of all of that?
automatic-azure
automatic-azure•10mo 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
yappiest-sapphire
yappiest-sapphireOP•10mo ago
Okay, thank you very much!
automatic-azure
automatic-azure•10mo 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
yappiest-sapphire
yappiest-sapphireOP•10mo ago
That would be much appreciated 😀
automatic-azure
automatic-azure•10mo 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
automatic-azure
automatic-azure•10mo ago
Please be aware that this uses internal types that might change @Chris Horobin maybe this is another candidate for a type primitive?
yappiest-sapphire
yappiest-sapphireOP•10mo ago
Thank you so much!

Did you find this page helpful?