diff --git a/packages/vue-query/src/__tests__/queryOptions.test-d.ts b/packages/vue-query/src/__tests__/queryOptions.test-d.ts index 9d1ec529dbf..929b1118de1 100644 --- a/packages/vue-query/src/__tests__/queryOptions.test-d.ts +++ b/packages/vue-query/src/__tests__/queryOptions.test-d.ts @@ -4,6 +4,7 @@ import { dataTagSymbol, skipToken } from '@tanstack/query-core' import { createKey } from '@tanstack/query-test-utils' import { QueryClient } from '../queryClient' import { queryOptions } from '../queryOptions' +import { useQueries } from '../useQueries' import { useQuery } from '../useQuery' import type { InitialDataFunction } from '@tanstack/query-core' @@ -54,6 +55,17 @@ describe('queryOptions', () => { expectTypeOf(data).toEqualTypeOf() }) + it('should work when passed to useQueries', () => { + const options = queryOptions({ + queryKey: createKey(), + queryFn: () => Promise.resolve(5), + }) + + const { value: queriesState } = useQueries({ queries: [options] }) + + expectTypeOf(queriesState[0].data).toEqualTypeOf() + }) + it('should work when passed to query', async () => { const options = queryOptions({ queryKey: ['key'], @@ -75,6 +87,27 @@ describe('queryOptions', () => { expectTypeOf(data).toEqualTypeOf() }) + it('should work when passed to query with enabled: false', async () => { + const options = queryOptions({ + queryKey: ['key'], + queryFn: () => Promise.resolve(5), + enabled: false, + }) + + const data = await new QueryClient().query(options) + expectTypeOf(data).toEqualTypeOf() + }) + + it('should work when passed to query with skipToken', async () => { + const options = queryOptions({ + queryKey: ['key'], + queryFn: skipToken, + }) + + const data = await new QueryClient().query(options) + expectTypeOf(data).toEqualTypeOf() + }) + it('should tag the queryKey with the result type of the QueryFn', () => { const key = createKey() const { queryKey: tagged } = queryOptions({ @@ -327,6 +360,26 @@ describe('queryOptions', () => { >() }) + it('should allow undefined response in initialData', () => { + assertType((id: string | null) => + queryOptions({ + queryKey: [...createKey(), id], + queryFn: () => + Promise.resolve({ + id: '1', + title: 'Do Laundry', + }), + initialData: () => + !id + ? undefined + : { + id, + title: 'Initial Data', + }, + }), + ) + }) + it('should allow accessing queryFn and other properties on the returned options object', () => { const options = queryOptions({ queryKey: createKey(),