Skip to content

Commit 020ac08

Browse files
lukemoralesTkDodo
andauthored
fix(types): repair wrong types passed to DataTag (#6699)
* fix: repair wrong types passed to `DataTag` * test: remove introduced changes and add test for the fixed behavior * Update packages/angular-query-experimental/src/__tests__/query-options.test-d.ts * Update packages/angular-query-experimental/src/__tests__/query-options.test-d.ts --------- Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
1 parent 22caf2a commit 020ac08

File tree

8 files changed

+62
-8
lines changed

8 files changed

+62
-8
lines changed

packages/angular-query-experimental/src/__tests__/query-options.test-d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ test('should tag the queryKey with unknown if there is no queryFn', () => {
7171
assertType<unknown>(queryKey[dataTagSymbol])
7272
})
7373

74+
test('should tag the queryKey with the result type of the QueryFn if select is used', () => {
75+
const { queryKey } = queryOptions({
76+
queryKey: ['key'],
77+
queryFn: () => Promise.resolve(5),
78+
select: (data) => data.toString(),
79+
})
80+
81+
assertType<number>(queryKey[dataTagSymbol])
82+
})
83+
7484
test('should return the proper type when passed to getQueryData', () => {
7585
const { queryKey } = queryOptions({
7686
queryKey: ['key'],

packages/angular-query-experimental/src/query-options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function queryOptions<
3131
>(
3232
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
3333
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
34-
queryKey: DataTag<TQueryKey, TData>
34+
queryKey: DataTag<TQueryKey, TQueryFnData>
3535
}
3636

3737
export function queryOptions<
@@ -42,7 +42,7 @@ export function queryOptions<
4242
>(
4343
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
4444
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
45-
queryKey: DataTag<TQueryKey, TData>
45+
queryKey: DataTag<TQueryKey, TQueryFnData>
4646
}
4747

4848
export function queryOptions(options: unknown) {

packages/react-query/src/__tests__/infiniteQueryOptions.types.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ describe('queryOptions', () => {
117117
return result
118118
})
119119
})
120+
it('should tag the queryKey with the result type of the QueryFn if select is used', () => {
121+
doNotExecute(() => {
122+
const { queryKey } = infiniteQueryOptions({
123+
queryKey: ['key'],
124+
queryFn: () => Promise.resolve('string'),
125+
select: (data) => data.pages,
126+
getNextPageParam: () => 1,
127+
initialPageParam: 1,
128+
})
129+
130+
const result: Expect<
131+
Equal<(typeof queryKey)[typeof dataTagSymbol], InfiniteData<string>>
132+
> = true
133+
return result
134+
})
135+
})
120136
it('should return the proper type when passed to getQueryData', () => {
121137
doNotExecute(() => {
122138
const { queryKey } = infiniteQueryOptions({

packages/react-query/src/__tests__/queryOptions.types.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,20 @@ describe('queryOptions', () => {
124124
return result
125125
})
126126
})
127+
it('should tag the queryKey with the result type of the QueryFn if select is used', () => {
128+
doNotExecute(() => {
129+
const { queryKey } = queryOptions({
130+
queryKey: ['key'],
131+
queryFn: () => Promise.resolve(5),
132+
select: (data) => data.toString(),
133+
})
134+
135+
const result: Expect<
136+
Equal<(typeof queryKey)[typeof dataTagSymbol], number>
137+
> = true
138+
return result
139+
})
140+
})
127141
it('should return the proper type when passed to getQueryData', () => {
128142
doNotExecute(() => {
129143
const { queryKey } = queryOptions({

packages/react-query/src/infiniteQueryOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function infiniteQueryOptions<
6262
TQueryKey,
6363
TPageParam
6464
> & {
65-
queryKey: DataTag<TQueryKey, TData>
65+
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
6666
}
6767

6868
export function infiniteQueryOptions<
@@ -86,7 +86,7 @@ export function infiniteQueryOptions<
8686
TQueryKey,
8787
TPageParam
8888
> & {
89-
queryKey: DataTag<TQueryKey, TData>
89+
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
9090
}
9191

9292
export function infiniteQueryOptions(options: unknown) {

packages/react-query/src/queryOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function queryOptions<
3131
>(
3232
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
3333
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
34-
queryKey: DataTag<TQueryKey, TData>
34+
queryKey: DataTag<TQueryKey, TQueryFnData>
3535
}
3636

3737
export function queryOptions<
@@ -42,7 +42,7 @@ export function queryOptions<
4242
>(
4343
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
4444
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
45-
queryKey: DataTag<TQueryKey, TData>
45+
queryKey: DataTag<TQueryKey, TQueryFnData>
4646
}
4747

4848
export function queryOptions(options: unknown) {

packages/vue-query/src/__tests__/queryOptions.types.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ describe('queryOptions', () => {
8383
return result
8484
})
8585
})
86+
it('should tag the queryKey with the result type of the QueryFn if select is used', () => {
87+
doNotExecute(() => {
88+
const { queryKey } = queryOptions({
89+
queryKey: ['key'],
90+
queryFn: () => Promise.resolve(5),
91+
select: (data) => data.toString(),
92+
})
93+
94+
const result: Expect<
95+
Equal<(typeof queryKey)[typeof dataTagSymbol], number>
96+
> = true
97+
return result
98+
})
99+
})
86100
it('should return the proper type when passed to getQueryData', () => {
87101
doNotExecute(() => {
88102
const { queryKey } = queryOptions({

packages/vue-query/src/queryOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function queryOptions<
1212
>(
1313
options: UndefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
1414
): UndefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
15-
queryKey: DataTag<TQueryKey, TData>
15+
queryKey: DataTag<TQueryKey, TQueryFnData>
1616
}
1717

1818
export function queryOptions<
@@ -23,7 +23,7 @@ export function queryOptions<
2323
>(
2424
options: DefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
2525
): DefinedInitialQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
26-
queryKey: DataTag<TQueryKey, TData>
26+
queryKey: DataTag<TQueryKey, TQueryFnData>
2727
}
2828

2929
export function queryOptions(options: unknown) {

0 commit comments

Comments
 (0)