T
TanStack2mo ago
xenial-black

Get the type of the search from a specific route ?

Hi, Is there a way to infer the search type from a specific route ? To have like :
export const Route = createFileRoute("/lol/live")({
component: RouteComponent,
validateSearch: (raw) v.parse(v.object({ /* some schema */}), raw)
});
type RouteSearch = /* some schema type */
export const Route = createFileRoute("/lol/live")({
component: RouteComponent,
validateSearch: (raw) v.parse(v.object({ /* some schema */}), raw)
});
type RouteSearch = /* some schema type */
I know I could do this extract the schema, put in in another file, import at in the route file and elsewhere where I need it, but I like my schema to be declared directly in the route file. (Can't export it because of vite single export per file rule).
1 Reply
xenial-black
xenial-blackOP2mo ago
nvm
type RouteSearchType = (typeof Route)["types"]["fullSearchSchema"];
type RouteSearchType = (typeof Route)["types"]["fullSearchSchema"];

Did you find this page helpful?