Replies: 5 comments 6 replies
-
And if there isn't, but you all are open to it, happy to make a PR? EDIT: Sorry, looks like I didn't have the latest version. I have the type now. But still getting the TS error below, so any help there would be greatly appreciated! EDIT 2: Think I confused myself...looks like it's not exposed, so maybe a PR would be welcome? |
Beta Was this translation helpful? Give feedback.
-
EDIT: Got this working by casting the map to Hmm, actually just playing with this locally seems I'm missing something still. Exposed Here is our wrapped hook. We essentially just add a
But that gives this TS error and I'm not sure where I'm going wrong?
|
Beta Was this translation helpful? Give feedback.
-
I'm getting better errors when removing the callside generics: - return useQueries<T>(
+ return useQueries( this should be the same because options are already bound to |
Beta Was this translation helpful? Give feedback.
-
Yeah, I think for now you might need to cast the map The cast is necessary in the current setup because I think something like should work for you and preserve the results? (I also added the extra `UseQueryOptions` in the map, so that when you destructure query on the line below it doesn't turn everything into `any`s)export function useConnectorQueries<T extends any[]>(
queries: [...QueriesOptions<T>]
): QueriesResults<T> {
return useQueries(
queries.map<UseQueryOptions>((query: UseQueryOptions) => {
const { queryFn, queryKey, queryVariables, onError,...rest } = query
return {
queryKey,
onError,
...rest,
queryFn: ({ queryKey }) => {
const [_key, ...args] = queryKey
return queryFn?.call({ connector }, ...args)
}
}
}) as [...QueriesOptions<T>]
)
} |
Beta Was this translation helpful? Give feedback.
-
[somewhat related] You've revealed a missing piece in the current types though: In theory you should also have been able to write something like the below, without any casting required, if you were working with an array rather than a tuple (if every export function useConnectorQueries<TQueryFnData, TError, TData, TQueryKey extends QueryKey>(
queries: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>[]
) {
...
} I don't know if this second example would better fit your use case... it doesn't work atm if you need to type your QK but I'll see if I can fix that (similar to #3208 ... in that issue we dealt with a strongly typed query key with a fixed-length argument, but not a dynamic array yet) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to access the type
QueriesOptions
? I'm working on wrappinguseQueries
and would like to type the argument the same way. Thanks for any help!Beta Was this translation helpful? Give feedback.
All reactions