How do I infer the type of all possible search parameters? #2826
Replies: 2 comments
-
I guess a side question would also be: is there a recommended pattern for handling building generic components that can interface with query params like this? |
Beta Was this translation helpful? Give feedback.
-
I have not tried this out yet, but I guess if you provide
That would enable you to build hooks around your shared functionality to encapsulate common logic. |
Beta Was this translation helpful? Give feedback.
-
I am in the midst of a migration from another router and I have some general components that interact with search params in a generic way. e.g.
These in turn call a hook like
useDataFilterQuery
:As you can see I have TODO in here where I cast the
queryKey
to be a valid return value ofuseSearch
. Ideally I'd like to extract the type of all possible query params so that I can make it the type forqueryKey
in this function, which should, I believe, also give me return type safety when I index intosearchParams
with that key. Is there a way to do this?Unrelated, but also related I am being forced to spread
searchParams
intonavigate
because of a type error when I follow the recommended pattern of:Tanstack version: 1.81.9
Typescript version: 5.5.3
Beta Was this translation helpful? Give feedback.
All reactions