@@ -52,6 +52,7 @@ import { useStableQueryArgs } from './useSerializedStableValue'
52
52
import type { UninitializedValue } from './constants'
53
53
import { UNINITIALIZED_VALUE } from './constants'
54
54
import { useShallowStableValue } from './useShallowStableValue'
55
+ import type { BaseQueryFn } from '../baseQueryTypes'
55
56
56
57
// Copy-pasted from React-Redux
57
58
export const useIsomorphicLayoutEffect =
@@ -97,7 +98,26 @@ export type UseQuery<D extends QueryDefinition<any, any, any, any>> = <
97
98
> (
98
99
arg : QueryArgFrom < D > | SkipToken ,
99
100
options ?: UseQuerySubscriptionOptions & UseQueryStateOptions < D , R >
100
- ) => UseQueryStateResult < D , R > & ReturnType < UseQuerySubscription < D > >
101
+ ) => UseQueryHookResult < D , R >
102
+
103
+ export type UseQueryHookResult <
104
+ D extends QueryDefinition < any , any , any , any > ,
105
+ R = UseQueryStateDefaultResult < D >
106
+ > = UseQueryStateResult < D , R > & UseQuerySubscriptionResult < D >
107
+
108
+ /**
109
+ * Helper type to manually type the result
110
+ * of the `useQuery` hook in userland code.
111
+ */
112
+ export type TypedUseQueryHookResult <
113
+ ResultType ,
114
+ QueryArg ,
115
+ BaseQuery extends BaseQueryFn ,
116
+ R = UseQueryStateDefaultResult <
117
+ QueryDefinition < QueryArg , BaseQuery , string , ResultType , string >
118
+ >
119
+ > = TypedUseQueryStateResult < ResultType , QueryArg , BaseQuery , R > &
120
+ TypedUseQuerySubscriptionResult < ResultType , QueryArg , BaseQuery >
101
121
102
122
interface UseQuerySubscriptionOptions extends SubscriptionOptions {
103
123
/**
@@ -162,7 +182,23 @@ export type UseQuerySubscription<
162
182
> = (
163
183
arg : QueryArgFrom < D > | SkipToken ,
164
184
options ?: UseQuerySubscriptionOptions
165
- ) => Pick < QueryActionCreatorResult < D > , 'refetch' >
185
+ ) => UseQuerySubscriptionResult < D >
186
+
187
+ export type UseQuerySubscriptionResult <
188
+ D extends QueryDefinition < any , any , any , any >
189
+ > = Pick < QueryActionCreatorResult < D > , 'refetch' >
190
+
191
+ /**
192
+ * Helper type to manually type the result
193
+ * of the `useQuerySubscription` hook in userland code.
194
+ */
195
+ export type TypedUseQuerySubscriptionResult <
196
+ ResultType ,
197
+ QueryArg ,
198
+ BaseQuery extends BaseQueryFn
199
+ > = UseQuerySubscriptionResult <
200
+ QueryDefinition < QueryArg , BaseQuery , string , ResultType , string >
201
+ >
166
202
167
203
export type UseLazyQueryLastPromiseInfo <
168
204
D extends QueryDefinition < any , any , any , any >
@@ -338,6 +374,19 @@ export type UseQueryStateResult<
338
374
R
339
375
> = NoInfer < R >
340
376
377
+ /**
378
+ * Helper type to manually type the result
379
+ * of the `useQueryState` hook in userland code.
380
+ */
381
+ export type TypedUseQueryStateResult <
382
+ ResultType ,
383
+ QueryArg ,
384
+ BaseQuery extends BaseQueryFn ,
385
+ R = UseQueryStateDefaultResult <
386
+ QueryDefinition < QueryArg , BaseQuery , string , ResultType , string >
387
+ >
388
+ > = NoInfer < R >
389
+
341
390
type UseQueryStateBaseResult < D extends QueryDefinition < any , any , any , any > > =
342
391
QuerySubState < D > & {
343
392
/**
@@ -435,6 +484,22 @@ export type UseMutationStateResult<
435
484
reset : ( ) => void
436
485
}
437
486
487
+ /**
488
+ * Helper type to manually type the result
489
+ * of the `useMutation` hook in userland code.
490
+ */
491
+ export type TypedUseMutationResult <
492
+ ResultType ,
493
+ QueryArg ,
494
+ BaseQuery extends BaseQueryFn ,
495
+ R = MutationResultSelectorResult <
496
+ MutationDefinition < QueryArg , BaseQuery , string , ResultType , string >
497
+ >
498
+ > = UseMutationStateResult <
499
+ MutationDefinition < QueryArg , BaseQuery , string , ResultType , string > ,
500
+ R
501
+ >
502
+
438
503
/**
439
504
* A React hook that lets you trigger an update request for a given endpoint, and subscribes the component to read the request status from the Redux store. The component will re-render as the loading status changes.
440
505
*
0 commit comments