Skip to content

type(vue-query): introduce ShallowOption to unify shallow type and JSDoc #9277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions packages/vue-query/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,18 @@ export type DeepUnwrapRef<T> = T extends UnwrapLeaf
}
: UnwrapRef<T>

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<TError = DefaultError> {
queries?: OmitKeyof<QueryObserverOptions<unknown, TError>, '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<unknown, TError, unknown, unknown> & {
/**
* 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<QueryObserverOptions<unknown, TError>, 'queryKey'> &
ShallowOption
mutations?: MutationObserverOptions<unknown, TError, unknown, unknown> &
ShallowOption
hydrate?: HydrateOptions['defaultOptions']
dehydrate?: DehydrateOptions
}
Expand Down
6 changes: 2 additions & 4 deletions packages/vue-query/src/useInfiniteQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
MaybeRef,
MaybeRefDeep,
MaybeRefOrGetter,
ShallowOption,
} from './types'
import type { QueryClient } from './queryClient'

Expand Down Expand Up @@ -55,9 +56,7 @@ export type UseInfiniteQueryOptions<
TPageParam
>[Property]
>
} & {
shallow?: boolean
}
} & ShallowOption
>

export type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 2 additions & 7 deletions packages/vue-query/src/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TData, TError, TVariables, TContext> = DistributiveOmit<
Expand All @@ -30,12 +30,7 @@ type MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<
>

type UseMutationOptionsBase<TData, TError, TVariables, TContext> =
MutationObserverOptions<TData, TError, TVariables, TContext> & {
/**
* 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<TData, TError, TVariables, TContext> & ShallowOption

export type UseMutationOptions<
TData = unknown,
Expand Down
5 changes: 2 additions & 3 deletions packages/vue-query/src/useQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -238,7 +238,7 @@ export function useQueries<
{
queries,
...options
}: {
}: ShallowOption & {
queries:
| MaybeRefDeep<UseQueriesOptionsArg<T>>
| MaybeRefDeep<
Expand All @@ -247,7 +247,6 @@ export function useQueries<
]
>
combine?: (result: UseQueriesResults<T>) => TCombinedResult
shallow?: boolean
},
queryClient?: QueryClient,
): Readonly<Ref<TCombinedResult>> {
Expand Down
8 changes: 2 additions & 6 deletions packages/vue-query/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
MaybeRef,
MaybeRefDeep,
MaybeRefOrGetter,
ShallowOption,
} from './types'
import type { QueryClient } from './queryClient'

Expand Down Expand Up @@ -50,12 +51,7 @@ export type UseQueryOptions<
DeepUnwrapRef<TQueryKey>
>[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<
Expand Down
Loading