|
1 |
| -/// <reference lib="dom" /> |
2 |
| - |
3 | 1 | declare module 'fetch-retry' {
|
4 |
| - const _fetch: typeof fetch; |
| 2 | + export type Fetch = (input: any, init?: any) => Promise<any>; |
5 | 3 |
|
6 |
| - type RequestDelayFunction = (( |
| 4 | + export type RequestDelayFunction<F extends Fetch> = ( |
7 | 5 | attempt: number,
|
8 | 6 | error: Error | null,
|
9 |
| - response: Response | null |
10 |
| - ) => number); |
| 7 | + response: Awaited<ReturnType<F>> | null, |
| 8 | + ) => number; |
11 | 9 |
|
12 |
| - type RequestRetryOnFunction = (( |
| 10 | + export type RequestRetryOnFunction<F extends Fetch> = ( |
13 | 11 | attempt: number,
|
14 | 12 | error: Error | null,
|
15 |
| - response: Response | null |
16 |
| - ) => boolean | Promise<boolean>); |
| 13 | + response: Awaited<ReturnType<F>> | null, |
| 14 | + ) => boolean | Promise<boolean>; |
17 | 15 |
|
18 |
| - export interface RequestInitRetryParams { |
| 16 | + export type RequestInitRetryParams<F extends Fetch> = { |
19 | 17 | retries?: number;
|
20 |
| - retryDelay?: number | RequestDelayFunction; |
21 |
| - retryOn?: number[] | RequestRetryOnFunction; |
22 |
| - } |
| 18 | + retryDelay?: number | RequestDelayFunction<F>; |
| 19 | + retryOn?: number[] | RequestRetryOnFunction<F>; |
| 20 | + }; |
23 | 21 |
|
24 |
| - export type RequestInitWithRetry = RequestInit & RequestInitRetryParams; |
| 22 | + export type RequestInitWithRetry<F extends Fetch> = Parameters<F>[1] & |
| 23 | + RequestInitRetryParams<F>; |
25 | 24 |
|
26 |
| - function fetchBuilder(fetch: typeof _fetch, defaults?: RequestInitRetryParams): ((input: Parameters<typeof _fetch>[0], init?: RequestInitWithRetry) => Promise<Response>); |
27 |
| - export default fetchBuilder; |
| 25 | + export default function fetchBuilder<F extends Fetch>( |
| 26 | + fetch: F, |
| 27 | + defaults?: RequestInitRetryParams<F>, |
| 28 | + ): (input: Parameters<F>[0], init?: RequestInitWithRetry<F>) => ReturnType<F>; |
28 | 29 | }
|
0 commit comments