@@ -79,9 +79,7 @@ export interface MutationHooks<
7979 useMutation : UseMutation < Definition >
8080}
8181
82- type IdleState < Arg > = Arg extends SkipToken
83- ? { isSkipped : true }
84- : { isSkipped : boolean }
82+ type SkippedState < Skipped extends boolean > = { isSkipped : Skipped }
8583
8684/**
8785 * A React hook that automatically triggers fetches of data from an endpoint, 'subscribes' the component to the cached data, and reads the request status and cached data from the Redux store. The component will re-render as the loading status changes and the data becomes available.
@@ -98,16 +96,43 @@ type IdleState<Arg> = Arg extends SkipToken
9896 * - Returns the latest request status and cached data from the Redux store
9997 * - Re-renders as the request status changes and data becomes available
10098 */
101- export type UseQuery < D extends QueryDefinition < any , any , any , any > > = <
102- R extends Record < string , any > = UseQueryStateDefaultResult < D > ,
103- Arg extends QueryArgFrom < D > | SkipToken = QueryArgFrom < D > | SkipToken
104- > (
105- arg : QueryArgFrom < D > | SkipToken ,
106- options ?: UseQuerySubscriptionOptions & UseQueryStateOptions < D , R >
107- ) => UseQueryStateResult < D , R > &
108- ReturnType < UseQuerySubscription < D > > &
109- Suspendable &
110- IdleState < Arg >
99+ export interface UseQuery < D extends QueryDefinition < any , any , any , any > > {
100+ // arg provided
101+ < R extends Record < string , any > = UseQueryStateDefaultResult < D > > (
102+ arg : QueryArgFrom < D > ,
103+ options ?: UseQuerySubscriptionOptions & UseQueryStateOptions < D , R >
104+ ) : UseQueryStateResult < D , R > &
105+ ReturnType < UseQuerySubscription < D > > &
106+ Suspendable &
107+ SkippedState < false >
108+ // skipped query
109+ < R extends Record < string , any > = UseQueryStateDefaultResult < D > > (
110+ arg : SkipToken ,
111+ options ?: UseQuerySubscriptionOptions & UseQueryStateOptions < D , R >
112+ ) : UseQueryStateResult < D , R > &
113+ ReturnType < UseQuerySubscription < D > > &
114+ Suspendable &
115+ SkippedState < true >
116+ < R extends Record < string , any > = UseQueryStateDefaultResult < D > > (
117+ arg : QueryArgFrom < D > | SkipToken ,
118+ options ?: UseQuerySubscriptionOptions & UseQueryStateOptions < D , R >
119+ ) : UseQueryStateResult < D , R > &
120+ ReturnType < UseQuerySubscription < D > > &
121+ Suspendable &
122+ SkippedState < boolean >
123+ }
124+
125+ /**
126+ * @internal
127+ */
128+ type UseQueryParams < D extends QueryDefinition < any , any , any , any > > = Parameters <
129+ UseQuery < D >
130+ >
131+
132+ /**
133+ * @internal
134+ */
135+ type AnyQueryDefinition = QueryDefinition < any , any , any , any , any >
111136
112137interface UseQuerySubscriptionOptions extends SubscriptionOptions {
113138 /**
@@ -551,7 +576,7 @@ const createSuspendablePromise = <
551576 Definitions ,
552577 Key
553578> ) : Suspendable [ 'getSuspendablePromise' ] => {
554- const retry = ( ) => {
579+ const fetchOnce = ( ) => {
555580 prefetch ( args , {
556581 force : true ,
557582 } )
@@ -565,27 +590,19 @@ const createSuspendablePromise = <
565590 let pendingPromise = api . util . getRunningOperationPromise ( name , args )
566591
567592 if ( ! pendingPromise ) {
568- prefetch ( args , {
569- force : true ,
570- } )
593+ fetchOnce ( )
571594
572595 pendingPromise = api . util . getRunningOperationPromise (
573596 name as any ,
574597 args
575598 )
576-
577- if ( ! pendingPromise ) {
578- throw new Error (
579- `[rtk-query][react]: invalid state error, expected getRunningOperationPromise(${ name } , ${ queryStateResults . requestId } ) to be defined`
580- )
581- }
582599 }
583600 return pendingPromise
584601 } else if ( queryStateResults . isError && ! queryStateResults . isFetching ) {
585602 throw new SuspenseQueryError (
586603 queryStateResults . error ,
587604 queryStateResults . endpointName + '' ,
588- retry
605+ fetchOnce
589606 )
590607 }
591608 }
@@ -938,7 +955,10 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
938955 [ trigger , queryStateResults , info ]
939956 )
940957 } ,
941- useQuery ( arg , options ) {
958+ useQuery (
959+ arg : UseQueryParams < AnyQueryDefinition > [ '0' ] ,
960+ options : UseQueryParams < AnyQueryDefinition > [ '1' ]
961+ ) {
942962 const isSkipped : boolean = arg === skipToken || ! ! options ?. skip
943963 const querySubscriptionResults = useQuerySubscription ( arg , options )
944964 const queryStateResults = useQueryState ( arg , {
0 commit comments