@@ -22,7 +22,7 @@ export type DeferFn<T> = (
2222
2323interface AbstractAction {
2424 type : string
25- meta : { counter : number ; [ meta : string ] : any }
25+ meta : { counter : number ; [ meta : string ] : any }
2626}
2727export type Start = AbstractAction & { type : "start" ; payload : ( ) => Promise < void > }
2828export type Cancel = AbstractAction & { type : "cancel" }
@@ -130,7 +130,7 @@ export type AsyncRejected<T> = AbstractState<T> & {
130130}
131131export type AsyncState < T > = AsyncInitial < T > | AsyncPending < T > | AsyncFulfilled < T > | AsyncRejected < T >
132132
133- export class Async < T > extends React . Component < AsyncProps < T > , AsyncState < T > > { }
133+ export class Async < T > extends React . Component < AsyncProps < T > , AsyncState < T > > { }
134134
135135export namespace Async {
136136 export function Initial < T > ( props : {
@@ -225,6 +225,17 @@ export function useFetch<T>(
225225 input : RequestInfo ,
226226 init ?: RequestInit ,
227227 options ?: FetchOptions < T >
228- ) : AsyncState < T >
228+ ) : AsyncInitialWithout < 'run' , T > & FetchRun < T > ;
229+
230+ // unfortunately, we cannot just omit K from AsyncInitial as that would unbox the Discriminated Union
231+ type AsyncInitialWithout < K extends keyof AsyncInitial < T > , T > = ( Omit < AsyncInitial < T > , K > | Omit < AsyncPending < T > , K > | Omit < AsyncFulfilled < T > , K > | Omit < AsyncRejected < T > , K > ) ;
232+
233+ type FetchRun < T > = {
234+ run ( overrideInit : Partial < RequestInit > ) : Promise < T >
235+ run ( overrideInit : ( init : RequestInit ) => RequestInit ) : Promise < T >
236+ run ( ignoredEvent : React . SyntheticEvent ) : Promise < T > ;
237+ run ( ignoredEvent : Event ) : Promise < T > ;
238+ run ( ) : Promise < T > ;
239+ } ;
229240
230241export default Async
0 commit comments