T
TanStack2y ago
eastern-cyan

Type errors with the useSearch hook strict:false

With useSearch({strict:false}) I receive type errors. Has anyone seeing this as well? I am using the newest version of the router
No description
5 Replies
eastern-cyan
eastern-cyanOP2y ago
the validateSearch looks like the following:
validateSearch: (
searchObj: Record<string, unknown>
): SignUpScreenSearchParams => {
return {
cid: (searchObj?.cid as string) || "",
mid: (searchObj?.mid as string) || "",
cname: (searchObj?.cname as string) || "",
};
}
validateSearch: (
searchObj: Record<string, unknown>
): SignUpScreenSearchParams => {
return {
cid: (searchObj?.cid as string) || "",
mid: (searchObj?.mid as string) || "",
cname: (searchObj?.cname as string) || "",
};
}
Did I miss some configuration to handle the searchParams correctly? The same type error is visible with useParams({strict:false}), is that intended?
eastern-cyan
eastern-cyanOP2y ago
I think that this example currently fails from the docs: https://tanstack.com/router/v1/docs/guide/type-safety#what-if-i-dont-know-the-route-or-its-a-shared-component-and-i-cant-pass-from If I use strict:false then there are no params or search params available
Type Safety | TanStack Router Docs
TanStack Router is built to be as type-safe as possible within the limits of the TypeScript compiler and runtime. This means that it's not only written in TypeScript, but that it also fully infers the types it's provided and tenaciously pipes them through the entire routing experience. Ultimately, this means that you write less types as a deve...
fair-rose
fair-rose2y ago
I have opened an issue for this. Look what I was recommended to do. https://github.com/TanStack/router/issues/1007
GitHub
useSearch hook with strict false type error · Issue #1007 · TanStac...
Describe the bug I have a route with some searchParams using validateSearch with zod. When using useSearch with strict=false in an abstract component, TypeScript throws the following error: "P...
genetic-orange
genetic-orange2y ago
eastern-cyan
eastern-cyanOP2y ago
Yes, v1.9 is fixing it with experimental_returnIntersection

Did you find this page helpful?