Skip to content

Commit 44563c3

Browse files
committed
test(vue-query): add type-check test for useInfiniteQuery with infiniteQueryOptions
1 parent 43049c5 commit 44563c3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { infiniteQueryOptions , useInfiniteQuery } from '@tanstack/vue-query'
2+
import { computed } from "vue";
3+
4+
export function sleep(ms: number) {
5+
return new Promise(resolve => setTimeout(resolve, ms));
6+
}
7+
8+
const options = {
9+
queryKey: ['infiniteQuery'],
10+
queryFn: () => sleep(0).then(() => 'Some data'),
11+
getNextPageParam: () => undefined,
12+
initialPageParam: 0,
13+
};
14+
const optionsComputed = computed(() => options);
15+
const optionsWrapped = infiniteQueryOptions(options);
16+
const optionsWrappedComputed = computed(() => infiniteQueryOptions(options));
17+
18+
const query1 = useInfiniteQuery(options);
19+
const query3 = useInfiniteQuery(optionsComputed);
20+
const query2 = useInfiniteQuery(optionsWrapped);
21+
const query4 = useInfiniteQuery(optionsWrappedComputed);

packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { computed, reactive } from 'vue-demi'
33
import { sleep } from '@tanstack/query-test-utils'
44
import { useInfiniteQuery } from '../useInfiniteQuery'
55
import type { InfiniteData } from '@tanstack/query-core'
6+
import { infiniteQueryOptions } from '../infiniteQueryOptions'
67

78
describe('Discriminated union return type', () => {
89
it('data should be possibly undefined by default', () => {
@@ -95,4 +96,18 @@ describe('Discriminated union return type', () => {
9596
expectTypeOf(query.data).toEqualTypeOf<InfiniteData<string, unknown>>()
9697
}
9798
})
99+
100+
it('should accept computed options with infiniteQueryOptions', () => {
101+
const options = computed(() => infiniteQueryOptions({
102+
queryKey: ['infiniteQuery'],
103+
queryFn: () => sleep(0).then(() => 'Some data'),
104+
getNextPageParam: () => undefined,
105+
initialPageParam: 0,
106+
}))
107+
const query = reactive(useInfiniteQuery(options))
108+
109+
if (query.isSuccess) {
110+
expectTypeOf(query.data).toEqualTypeOf<InfiniteData<string, unknown>>()
111+
}
112+
})
98113
})

0 commit comments

Comments
 (0)