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