Skip to content

Commit e45dea8

Browse files
fix(vue-query): update initialData type to allow InitialDataFunction and NonUndefinedGuard, similar to react-query (#9073)
* fix(vue-query): update `initialData` type to allow InitialDataFunction and NonUndefinedGuard, similar to react-query * ci: apply automated fixes * test: update types to include `undefined` in useQueries and useQuery tests in vue-query * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent b8ea29e commit e45dea8

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

packages/vue-query/src/__tests__/useQueries.test-d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('UseQueries config object overload', () => {
3535
})
3636

3737
expectTypeOf(queriesState[0].data).toEqualTypeOf<{ wow: boolean }>()
38-
expectTypeOf(queriesState[1].data).toEqualTypeOf<string>()
38+
expectTypeOf(queriesState[1].data).toEqualTypeOf<string | undefined>()
3939
expectTypeOf(queriesState[2].data).toEqualTypeOf<string | undefined>()
4040
})
4141

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

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

57-
expectTypeOf(queriesState[0].data).toEqualTypeOf<{ wow: boolean }>()
57+
expectTypeOf(queriesState[0].data).toEqualTypeOf<
58+
{ wow: boolean } | undefined
59+
>()
5860
})
5961

6062
it('should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQueries', () => {

packages/vue-query/src/__tests__/useQuery.test-d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('useQuery', () => {
2323
}),
2424
)
2525

26-
expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>()
26+
expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>()
2727
})
2828

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

43-
expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>()
43+
expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>()
4444
})
4545

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

77-
expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>()
77+
expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>()
7878
})
7979

8080
it('TData should have undefined in the union when initialData is NOT provided', () => {

packages/vue-query/src/useQuery.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useBaseQuery } from './useBaseQuery'
33
import type {
44
DefaultError,
55
DefinedQueryObserverResult,
6+
InitialDataFunction,
67
QueryKey,
78
QueryObserverOptions,
89
} from '@tanstack/query-core'
@@ -64,7 +65,10 @@ export type UndefinedInitialQueryOptions<
6465
TData = TQueryFnData,
6566
TQueryKey extends QueryKey = QueryKey,
6667
> = UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> & {
67-
initialData?: undefined
68+
initialData?:
69+
| undefined
70+
| InitialDataFunction<NonUndefinedGuard<TQueryFnData>>
71+
| NonUndefinedGuard<TQueryFnData>
6872
}
6973

7074
export type DefinedInitialQueryOptions<

0 commit comments

Comments
 (0)