From 1e4efea04b00058f3a9567d2795211a4bb4450bc Mon Sep 17 00:00:00 2001 From: Alex Liu Date: Tue, 25 Feb 2025 00:24:16 +0800 Subject: [PATCH] types(vue-query): add `shallow` support to `QueryClientConfig` --- packages/vue-query/src/queryClient.ts | 3 +- packages/vue-query/src/types.ts | 36 ++++++++++++++++++++++++ packages/vue-query/src/useMutation.ts | 3 ++ packages/vue-query/src/useQuery.ts | 3 ++ packages/vue-query/src/vueQueryPlugin.ts | 2 +- 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/packages/vue-query/src/queryClient.ts b/packages/vue-query/src/queryClient.ts index 7712268bb7..02a07b3390 100644 --- a/packages/vue-query/src/queryClient.ts +++ b/packages/vue-query/src/queryClient.ts @@ -5,7 +5,7 @@ import { QueryCache } from './queryCache' import { MutationCache } from './mutationCache' import type { UseQueryOptions } from './useQuery' import type { Ref } from 'vue-demi' -import type { MaybeRefDeep, NoUnknown } from './types' +import type { MaybeRefDeep, NoUnknown, QueryClientConfig } from './types' import type { CancelOptions, DataTag, @@ -22,7 +22,6 @@ import type { MutationObserverOptions, NoInfer, OmitKeyof, - QueryClientConfig, QueryFilters, QueryKey, QueryObserverOptions, diff --git a/packages/vue-query/src/types.ts b/packages/vue-query/src/types.ts index 4a5d82671c..b6ab0ee210 100644 --- a/packages/vue-query/src/types.ts +++ b/packages/vue-query/src/types.ts @@ -1,3 +1,13 @@ +import type { + DefaultError, + DehydrateOptions, + HydrateOptions, + MutationCache, + MutationObserverOptions, + OmitKeyof, + QueryCache, + QueryObserverOptions, +} from '@tanstack/query-core' import type { ComputedRef, Ref, UnwrapRef } from 'vue-demi' type Primitive = string | number | boolean | bigint | symbol | undefined | null @@ -48,3 +58,29 @@ export type DeepUnwrapRef = T extends UnwrapLeaf export type DistributiveOmit = T extends any ? Omit : never + +export interface DefaultOptions { + queries?: OmitKeyof< + QueryObserverOptions, + 'queryKey' | 'queryFn' + > & { + /** + * 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 + } + hydrate?: HydrateOptions['defaultOptions'] + dehydrate?: DehydrateOptions +} + +export interface QueryClientConfig { + queryCache?: QueryCache + mutationCache?: MutationCache + defaultOptions?: DefaultOptions +} diff --git a/packages/vue-query/src/useMutation.ts b/packages/vue-query/src/useMutation.ts index 91aff2655b..e68983106a 100644 --- a/packages/vue-query/src/useMutation.ts +++ b/packages/vue-query/src/useMutation.ts @@ -29,6 +29,9 @@ 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 } diff --git a/packages/vue-query/src/useQuery.ts b/packages/vue-query/src/useQuery.ts index af3f1ea31d..a27258c2aa 100644 --- a/packages/vue-query/src/useQuery.ts +++ b/packages/vue-query/src/useQuery.ts @@ -51,6 +51,9 @@ export type UseQueryOptions< >[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 } > diff --git a/packages/vue-query/src/vueQueryPlugin.ts b/packages/vue-query/src/vueQueryPlugin.ts index 47997c0068..04d254ffdb 100644 --- a/packages/vue-query/src/vueQueryPlugin.ts +++ b/packages/vue-query/src/vueQueryPlugin.ts @@ -4,7 +4,7 @@ import { isServer } from '@tanstack/query-core' import { QueryClient } from './queryClient' import { getClientKey } from './utils' import { setupDevtools } from './devtools/devtools' -import type { QueryClientConfig } from '@tanstack/query-core' +import type { QueryClientConfig } from './types' type ClientPersister = (client: QueryClient) => [() => void, Promise]