@@ -6,7 +6,7 @@ export type DeferFn<T> = (args: any[], props: object, controller: AbortControlle
66
77interface AbstractAction {
88 type : string
9- meta : { counter : number ; [ meta : string ] : any }
9+ meta : { counter : number ; [ meta : string ] : any }
1010}
1111export type Start = AbstractAction & { type : "start" ; payload : ( ) => Promise < void > }
1212export type Cancel = AbstractAction & { type : "cancel" }
@@ -114,7 +114,7 @@ export type AsyncRejected<T> = AbstractState<T> & {
114114}
115115export type AsyncState < T > = AsyncInitial < T > | AsyncPending < T > | AsyncFulfilled < T > | AsyncRejected < T >
116116
117- export class Async < T > extends Component < AsyncProps < T > , AsyncState < T > > { }
117+ export class Async < T > extends Component < AsyncProps < T > , AsyncState < T > > { }
118118
119119export namespace Async {
120120 export function Initial < T > ( props : { children ?: AsyncChildren < T > ; persist ?: boolean } ) : JSX . Element
@@ -161,6 +161,17 @@ export function useFetch<T>(
161161 input : RequestInfo ,
162162 init ?: RequestInit ,
163163 options ?: FetchOptions < T >
164- ) : AsyncState < T >
164+ ) : AsyncInitialWithout < 'run' , T > & FetchRun < T > ;
165+
166+ // unfortunately, we cannot just omit K from AsyncInitial as that would unbox the Discriminated Union
167+ type AsyncInitialWithout < K extends keyof AsyncInitial < T > , T > = ( Omit < AsyncInitial < T > , K > | Omit < AsyncPending < T > , K > | Omit < AsyncFulfilled < T > , K > | Omit < AsyncRejected < T > , K > ) ;
168+
169+ type FetchRun < T > = {
170+ run ( overrideInit : Partial < RequestInit > ) : Promise < T >
171+ run ( overrideInit : ( init : RequestInit ) => RequestInit ) : Promise < T >
172+ run ( ignoredEvent : React . SyntheticEvent ) : Promise < T > ;
173+ run ( ignoredEvent : Event ) : Promise < T > ;
174+ run ( ) : Promise < T > ;
175+ } ;
165176
166177export default Async
0 commit comments