Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/vue-query/src/__tests__/useQueries.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('UseQueries config object overload', () => {
})

expectTypeOf(queriesState[0].data).toEqualTypeOf<{ wow: boolean }>()
expectTypeOf(queriesState[1].data).toEqualTypeOf<string>()
expectTypeOf(queriesState[1].data).toEqualTypeOf<string | undefined>()
expectTypeOf(queriesState[2].data).toEqualTypeOf<string | undefined>()
})

Expand All @@ -54,7 +54,9 @@ describe('UseQueries config object overload', () => {

const { value: queriesState } = useQueries({ queries: [options] })

expectTypeOf(queriesState[0].data).toEqualTypeOf<{ wow: boolean }>()
expectTypeOf(queriesState[0].data).toEqualTypeOf<
{ wow: boolean } | undefined
>()
})

it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQueries', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/vue-query/src/__tests__/useQuery.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('useQuery', () => {
}),
)

expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>()
expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>()
})

it('TData should be defined when passed through queryOptions', () => {
Expand All @@ -40,7 +40,7 @@ describe('useQuery', () => {
})
const { data } = reactive(useQuery(options))

expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>()
expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>()
})

it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery', () => {
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('useQuery', () => {
}),
)

expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>()
expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>()
})

it('TData should have undefined in the union when initialData is NOT provided', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/vue-query/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useBaseQuery } from './useBaseQuery'
import type {
DefaultError,
DefinedQueryObserverResult,
InitialDataFunction,
QueryKey,
QueryObserverOptions,
} from '@tanstack/query-core'
Expand Down Expand Up @@ -64,7 +65,10 @@ export type UndefinedInitialQueryOptions<
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
> = UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> & {
initialData?: undefined
initialData?:
| undefined
| InitialDataFunction<NonUndefinedGuard<TQueryFnData>>
| NonUndefinedGuard<TQueryFnData>
}

export type DefinedInitialQueryOptions<
Expand Down
Loading