Skip to content

Commit 05ebcce

Browse files
authored
fix(query): conflict types when override options (#190)
* fix(query): conflict types when override options * docs: `skipToken` for Disabling Queries
1 parent cd121e3 commit 05ebcce

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

apps/content/docs/tanstack-query/react.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,26 @@ Integrate oRPC React Query utils into your React app with Context:
115115

116116
const query = useQuery(orpc.planet.find.queryOptions({ input: { id: 123 } }))
117117
```
118+
119+
## `skipToken` for Disabling Queries
120+
121+
You can still use [skipToken](https://tanstack.com/query/latest/docs/framework/react/guides/disabling-queries/#typesafe-disabling-of-queries-using-skiptoken) by conditionally overriding the `queryFn` property:
122+
123+
```ts twoslash
124+
import type { router } from './shared/planet'
125+
import type { RouterClient } from '@orpc/server'
126+
import type { RouterUtils } from '@orpc/react-query'
127+
declare const orpc: RouterUtils<RouterClient<typeof router>>
128+
declare const condition: boolean
129+
// ---cut---
130+
import { skipToken, useQuery } from '@tanstack/react-query'
131+
132+
const options = orpc.planet.find.queryOptions({
133+
input: { id: 123 },
134+
})
135+
136+
const query = useQuery({
137+
...options,
138+
queryFn: condition ? skipToken : options.queryFn,
139+
})
140+
```

packages/react-query/src/procedure-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ export interface ProcedureUtils<TClientContext extends ClientContext, TInput, TO
1111
...rest: MaybeOptionalOptions<
1212
U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>
1313
>
14-
): NoInfer<U & QueryOptionsBase<TOutput, TError>>
14+
): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>
1515

1616
infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput, UPageParam>>(
1717
options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>
18-
): NoInfer<U & InfiniteOptionsBase<TOutput, TError, UPageParam>>
18+
): NoInfer<U & Omit<InfiniteOptionsBase<TOutput, TError, UPageParam>, keyof U>>
1919

2020
mutationOptions<U, UMutationContext>(
2121
...rest: MaybeOptionalOptions<
2222
U & MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>
2323
>
24-
): NoInfer<U & MutationOptionsBase<TInput, TOutput, TError>>
24+
): NoInfer<U & Omit<MutationOptionsBase<TInput, TOutput, TError>, keyof U>>
2525
}
2626

2727
export function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(

packages/vue-query/src/procedure-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ export interface ProcedureUtils<TClientContext extends ClientContext, TInput, TO
1313
...rest: MaybeOptionalOptions<
1414
U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>
1515
>
16-
): NoInfer<U & QueryOptionsBase<TOutput, TError>>
16+
): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>
1717

1818
infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput, UPageParam>>(
1919
options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>
20-
): NoInfer<U & InfiniteOptionsBase<TOutput, TError, UPageParam>>
20+
): NoInfer<U & Omit<InfiniteOptionsBase<TOutput, TError, UPageParam>, keyof U>>
2121

2222
mutationOptions<U, UMutationContext>(
2323
...rest: MaybeOptionalOptions<
2424
U & MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>
2525
>
26-
): NoInfer<U & MutationOptionsBase<TInput, TOutput, TError>>
26+
): NoInfer<U & Omit<MutationOptionsBase<TInput, TOutput, TError>, keyof U>>
2727
}
2828

2929
export function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError extends Error>(

packages/vue-query/src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ClientContext } from '@orpc/client'
22
import type { AnyFunction, SetOptional } from '@orpc/shared'
3-
import type { Enabled, MutationObserverOptions, QueryFunctionContext, QueryKey, QueryObserverOptions, UseInfiniteQueryOptions } from '@tanstack/vue-query'
3+
import type { MutationObserverOptions, QueryFunctionContext, QueryKey, QueryObserverOptions, UseInfiniteQueryOptions } from '@tanstack/vue-query'
44
import type { ComputedRef, MaybeRef, MaybeRefOrGetter } from 'vue'
55

66
/**
@@ -23,9 +23,9 @@ export type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput
2323
MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>[P]>
2424
}
2525
& {
26-
enabled?: MaybeRefOrGetter<Enabled<TOutput, TError, TSelectData>>
27-
queryKey?: MaybeRefDeep<QueryKey>
28-
shallow?: boolean
26+
enabled?: MaybeRefOrGetter<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['enabled']>
27+
queryKey?: MaybeRefDeep<QueryObserverOptions<TOutput, TError, TSelectData, TOutput>['queryKey']>
28+
shallow?: MaybeRef<boolean>
2929
}
3030

3131
export interface QueryOptionsBase<TOutput, TError extends Error> {

0 commit comments

Comments
 (0)