diff --git a/packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx b/packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx index a835e20fbc..9163cd2482 100644 --- a/packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx +++ b/packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx @@ -2,6 +2,7 @@ import { describe, expectTypeOf, it } from 'vitest' import { computed, reactive } from 'vue-demi' import { sleep } from '@tanstack/query-test-utils' import { useInfiniteQuery } from '../useInfiniteQuery' +import { infiniteQueryOptions } from '../infiniteQueryOptions' import type { InfiniteData } from '@tanstack/query-core' describe('Discriminated union return type', () => { @@ -95,4 +96,35 @@ describe('Discriminated union return type', () => { expectTypeOf(query.data).toEqualTypeOf>() } }) + + it('should accept computed options using infiniteQueryOptions', () => { + const options = computed(() => + infiniteQueryOptions({ + queryKey: ['infiniteQuery'], + queryFn: () => sleep(0).then(() => 'Some data'), + getNextPageParam: () => undefined, + initialPageParam: 0, + }), + ) + const query = reactive(useInfiniteQuery(options)) + + if (query.isSuccess) { + expectTypeOf(query.data).toEqualTypeOf>() + } + }) + + it('should accept plain options using infiniteQueryOptions', () => { + const options = () => + infiniteQueryOptions({ + queryKey: ['infiniteQuery'], + queryFn: () => sleep(0).then(() => 'Some data'), + getNextPageParam: () => undefined, + initialPageParam: 0, + }) + const query = reactive(useInfiniteQuery(options)) + + if (query.isSuccess) { + expectTypeOf(query.data).toEqualTypeOf>() + } + }) }) diff --git a/packages/vue-query/src/useBaseQuery.ts b/packages/vue-query/src/useBaseQuery.ts index 1b6786837b..2e9963e5f6 100644 --- a/packages/vue-query/src/useBaseQuery.ts +++ b/packages/vue-query/src/useBaseQuery.ts @@ -22,6 +22,7 @@ import type { import type { QueryClient } from './queryClient' import type { UseQueryOptions } from './useQuery' import type { UseInfiniteQueryOptions } from './useInfiniteQuery' +import type { MaybeRefOrGetter } from './types' export type UseBaseQueryReturnType< TData, @@ -58,13 +59,15 @@ export function useBaseQuery< TPageParam, >( Observer: typeof QueryObserver, - options: UseQueryOptionsGeneric< - TQueryFnData, - TError, - TData, - TQueryData, - TQueryKey, - TPageParam + options: MaybeRefOrGetter< + UseQueryOptionsGeneric< + TQueryFnData, + TError, + TData, + TQueryData, + TQueryKey, + TPageParam + > >, queryClient?: QueryClient, ): UseBaseQueryReturnType { diff --git a/packages/vue-query/src/useInfiniteQuery.ts b/packages/vue-query/src/useInfiniteQuery.ts index c8282ea9c1..99c14c8648 100644 --- a/packages/vue-query/src/useInfiniteQuery.ts +++ b/packages/vue-query/src/useInfiniteQuery.ts @@ -72,12 +72,14 @@ export function useInfiniteQuery< TQueryKey extends QueryKey = QueryKey, TPageParam = unknown, >( - options: DefinedInitialDataInfiniteOptions< - TQueryFnData, - TError, - TData, - TQueryKey, - TPageParam + options: MaybeRefOrGetter< + DefinedInitialDataInfiniteOptions< + TQueryFnData, + TError, + TData, + TQueryKey, + TPageParam + > >, queryClient?: QueryClient, ): UseInfiniteQueryReturnType @@ -89,12 +91,14 @@ export function useInfiniteQuery< TQueryKey extends QueryKey = QueryKey, TPageParam = unknown, >( - options: UndefinedInitialDataInfiniteOptions< - TQueryFnData, - TError, - TData, - TQueryKey, - TPageParam + options: MaybeRefOrGetter< + UndefinedInitialDataInfiniteOptions< + TQueryFnData, + TError, + TData, + TQueryKey, + TPageParam + > >, queryClient?: QueryClient, ): UseInfiniteQueryReturnType @@ -106,18 +110,14 @@ export function useInfiniteQuery< TQueryKey extends QueryKey = QueryKey, TPageParam = unknown, >( - options: UseInfiniteQueryOptions< - TQueryFnData, - TError, - TData, - TQueryKey, - TPageParam + options: MaybeRefOrGetter< + UseInfiniteQueryOptions >, queryClient?: QueryClient, ): UseInfiniteQueryReturnType export function useInfiniteQuery( - options: UseInfiniteQueryOptions, + options: MaybeRefOrGetter, queryClient?: QueryClient, ) { return useBaseQuery(