TanStackT
TanStack2y ago
11 replies
abstract-purple

Strongly typing useQueries

Hi I am trying to use
useQueries
, and I have doubt with Typescript,
I am trying to call multiple fetch functions in useQueries and it returns an array of combined types. I was wondering is there any way to strongly type the array with query v5:

in the given code, is there any way to return the types like [string, date, number] considering those functions returns these types correspondingly?
const { data, isSuccess, isError } = useQueries({
    queries: 
        [
          {
            queryKey: ['address'],
            queryFn: fetchAddress(),
          },
          {
            queryKey: ['date'],
            queryFn: fetchDate(),
          },
          {
            queryKey: ['registrationNumber'],
            queryFn: fetchRegNo(),
          },
        ],
    combine: (results) => ({
      data: results.map((result) => result.data),
      pending: results.some((result) => result.isPending),
      isLoading: results.some((result) => result.isLoading),
      isSuccess: results.every((result) => result.isSuccess),
      isError: results.some((result) => result.isError),
    }),
  });
Was this page helpful?