@@ -53,6 +53,7 @@ import { useStableQueryArgs } from './useSerializedStableValue'
5353import type { UninitializedValue } from './constants'
5454import { UNINITIALIZED_VALUE } from './constants'
5555import { useShallowStableValue } from './useShallowStableValue'
56+ import type { BaseQueryFn } from '../baseQueryTypes'
5657
5758// Copy-pasted from React-Redux
5859export const useIsomorphicLayoutEffect =
@@ -98,7 +99,26 @@ export type UseQuery<D extends QueryDefinition<any, any, any, any>> = <
9899> (
99100 arg : QueryArgFrom < D > | SkipToken ,
100101 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 >
102122
103123interface UseQuerySubscriptionOptions extends SubscriptionOptions {
104124 /**
@@ -163,7 +183,23 @@ export type UseQuerySubscription<
163183> = (
164184 arg : QueryArgFrom < D > | SkipToken ,
165185 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+ >
167203
168204export type UseLazyQueryLastPromiseInfo <
169205 D extends QueryDefinition < any , any , any , any >
@@ -339,6 +375,19 @@ export type UseQueryStateResult<
339375 R
340376> = NoInfer < R >
341377
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+
342391type UseQueryStateBaseResult < D extends QueryDefinition < any , any , any , any > > =
343392 QuerySubState < D > & {
344393 /**
@@ -436,6 +485,22 @@ export type UseMutationStateResult<
436485 reset : ( ) => void
437486}
438487
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+
439504/**
440505 * 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.
441506 *
0 commit comments