diff --git a/packages/vue-query/src/types.ts b/packages/vue-query/src/types.ts index afabb55ea3..eb793c811e 100644 --- a/packages/vue-query/src/types.ts +++ b/packages/vue-query/src/types.ts @@ -55,19 +55,18 @@ export type DeepUnwrapRef = T extends UnwrapLeaf } : UnwrapRef +export type ShallowOption = { + /** + * Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive. + */ + shallow?: boolean +} + export interface DefaultOptions { - queries?: OmitKeyof, 'queryKey'> & { - /** - * Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive. - */ - shallow?: boolean - } - mutations?: MutationObserverOptions & { - /** - * Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive. - */ - shallow?: boolean - } + queries?: OmitKeyof, 'queryKey'> & + ShallowOption + mutations?: MutationObserverOptions & + ShallowOption hydrate?: HydrateOptions['defaultOptions'] dehydrate?: DehydrateOptions } diff --git a/packages/vue-query/src/useInfiniteQuery.ts b/packages/vue-query/src/useInfiniteQuery.ts index f16eb80dff..c8282ea9c1 100644 --- a/packages/vue-query/src/useInfiniteQuery.ts +++ b/packages/vue-query/src/useInfiniteQuery.ts @@ -20,6 +20,7 @@ import type { MaybeRef, MaybeRefDeep, MaybeRefOrGetter, + ShallowOption, } from './types' import type { QueryClient } from './queryClient' @@ -55,9 +56,7 @@ export type UseInfiniteQueryOptions< TPageParam >[Property] > - } & { - shallow?: boolean - } + } & ShallowOption > export type UseInfiniteQueryReturnType = UseBaseQueryReturnType< @@ -122,7 +121,6 @@ export function useInfiniteQuery( queryClient?: QueryClient, ) { return useBaseQuery( - // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion InfiniteQueryObserver as typeof QueryObserver, options, queryClient, diff --git a/packages/vue-query/src/useMutation.ts b/packages/vue-query/src/useMutation.ts index 40b680307b..d507bbc74f 100644 --- a/packages/vue-query/src/useMutation.ts +++ b/packages/vue-query/src/useMutation.ts @@ -21,7 +21,7 @@ import type { MutationObserverOptions, MutationObserverResult, } from '@tanstack/query-core' -import type { MaybeRefDeep } from './types' +import type { MaybeRefDeep, ShallowOption } from './types' import type { QueryClient } from './queryClient' type MutationResult = DistributiveOmit< @@ -30,12 +30,7 @@ type MutationResult = DistributiveOmit< > type UseMutationOptionsBase = - MutationObserverOptions & { - /** - * Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive. - */ - shallow?: boolean - } + MutationObserverOptions & ShallowOption export type UseMutationOptions< TData = unknown, diff --git a/packages/vue-query/src/useQueries.ts b/packages/vue-query/src/useQueries.ts index 48af3dfa98..4d06be76d7 100644 --- a/packages/vue-query/src/useQueries.ts +++ b/packages/vue-query/src/useQueries.ts @@ -24,7 +24,7 @@ import type { } from '@tanstack/query-core' import type { UseQueryOptions } from './useQuery' import type { QueryClient } from './queryClient' -import type { DeepUnwrapRef, MaybeRefDeep } from './types' +import type { DeepUnwrapRef, MaybeRefDeep, ShallowOption } from './types' // This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`. // `placeholderData` function does not have a parameter @@ -238,7 +238,7 @@ export function useQueries< { queries, ...options - }: { + }: ShallowOption & { queries: | MaybeRefDeep> | MaybeRefDeep< @@ -247,7 +247,6 @@ export function useQueries< ] > combine?: (result: UseQueriesResults) => TCombinedResult - shallow?: boolean }, queryClient?: QueryClient, ): Readonly> { diff --git a/packages/vue-query/src/useQuery.ts b/packages/vue-query/src/useQuery.ts index 168eb36095..43c8c20548 100644 --- a/packages/vue-query/src/useQuery.ts +++ b/packages/vue-query/src/useQuery.ts @@ -14,6 +14,7 @@ import type { MaybeRef, MaybeRefDeep, MaybeRefOrGetter, + ShallowOption, } from './types' import type { QueryClient } from './queryClient' @@ -50,12 +51,7 @@ export type UseQueryOptions< DeepUnwrapRef >[Property] > - } & { - /** - * Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive. - */ - shallow?: boolean - } + } & ShallowOption > export type UndefinedInitialQueryOptions<