Skip to content

Commit a4efa6e

Browse files
authored
fix(tanstack): incorrect vue-query options typing for vue-query v5 (#1565)
1 parent ac2b291 commit a4efa6e

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

packages/plugins/tanstack-query/src/generator.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ function makeBaseImports(target: TargetFramework, version: TanStackVersion) {
624624
return [
625625
`import type { UseMutationOptions, UseQueryOptions, UseInfiniteQueryOptions, InfiniteData } from '@tanstack/vue-query';`,
626626
`import { getHooksContext } from '${runtimeImportBase}/${target}';`,
627-
`import type { MaybeRefOrGetter, ComputedRef } from 'vue';`,
627+
`import type { MaybeRefOrGetter, ComputedRef, UnwrapRef } from 'vue';`,
628628
...shared,
629629
];
630630
}
@@ -674,7 +674,9 @@ function makeQueryOptions(
674674
.with('vue', () => {
675675
const baseOption = infinite
676676
? `Omit<UseInfiniteQueryOptions<${returnType}, TError, InfiniteData<${dataType}>>, 'queryKey' | 'initialPageParam'>`
677-
: `Omit<UseQueryOptions<${returnType}, TError, ${dataType}>, 'queryKey'>`;
677+
: version === 'v4'
678+
? `Omit<UseQueryOptions<${returnType}, TError, ${dataType}>, 'queryKey'>`
679+
: `Omit<UnwrapRef<UseQueryOptions<${returnType}, TError, ${dataType}>>, 'queryKey'>`;
678680
return `MaybeRefOrGetter<${baseOption}> | ComputedRef<${baseOption}>`;
679681
})
680682
.with('svelte', () =>

packages/plugins/tanstack-query/tests/plugin.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ model Foo {
5454
import { useFindFirstpost_Item, useInfiniteFindManypost_Item, useCreatepost_Item } from './hooks';
5555
5656
function query() {
57-
const { data } = useFindFirstpost_Item({include: { author: true }});
57+
const { data } = useFindFirstpost_Item({include: { author: true }}, { enabled: true, optimisticUpdate: false });
5858
console.log(data?.viewCount);
5959
console.log(data?.author?.email);
6060
}
6161
6262
function infiniteQuery() {
6363
const { data, fetchNextPage, hasNextPage } = useInfiniteFindManypost_Item();
6464
useInfiniteFindManypost_Item({ where: { published: true } });
65-
useInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null });
65+
useInfiniteFindManypost_Item(undefined, { enabled: true, getNextPageParam: () => null });
6666
console.log(data?.pages[0][0].published);
6767
console.log(data?.pageParams[0]);
6868
}
@@ -143,14 +143,14 @@ ${sharedModel}
143143
import { useFindFirstpost_Item, useInfiniteFindManypost_Item, useCreatepost_Item } from './hooks';
144144
145145
function query() {
146-
const { data } = useFindFirstpost_Item({include: { author: true }});
146+
const { data } = useFindFirstpost_Item({include: { author: true }}, { enabled: true, optimisticUpdate: false });
147147
console.log(data.value?.viewCount);
148148
console.log(data.value?.author?.email);
149149
}
150150
151151
function infiniteQuery() {
152152
const { data, fetchNextPage, hasNextPage } = useInfiniteFindManypost_Item();
153-
useInfiniteFindManypost_Item({ where: { published: true } });
153+
useInfiniteFindManypost_Item({ where: { published: true } }, { enabled: true, getNextPageParam: () => null });
154154
useInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null });
155155
console.log(data.value?.pages[0][0].published);
156156
console.log(data.value?.pageParams[0]);
@@ -217,15 +217,15 @@ ${sharedModel}
217217
import { useFindFirstpost_Item, useInfiniteFindManypost_Item, useCreatepost_Item } from './hooks';
218218
219219
function query() {
220-
const { data } = get(useFindFirstpost_Item({include: { author: true }}));
220+
const { data } = get(useFindFirstpost_Item({include: { author: true }}, { enabled: true, optimisticUpdate: false }));
221221
console.log(data?.viewCount);
222222
console.log(data?.author?.email);
223223
}
224224
225225
function infiniteQuery() {
226226
const { data, fetchNextPage, hasNextPage } = get(useInfiniteFindManypost_Item());
227227
useInfiniteFindManypost_Item({ where: { published: true } });
228-
useInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null });
228+
useInfiniteFindManypost_Item(undefined, { enabled: true, getNextPageParam: () => null });
229229
console.log(data?.pages[0][0].published);
230230
console.log(data?.pageParams[0]);
231231
}

0 commit comments

Comments
 (0)