mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-30 01:47:21 +08:00
The async-retry function has a generic type parameter `A` and TypeScript is unable to infer the concret type when the `bail` function, whose type references the generic type, is specified. Reading the source and API documentation of async-retry, `bail` returns nothing so `void` is the right type here. This in turn fixes inference of the generic type parameter `A`. Tested by adding some expected return types to the test file. The type checks failed before this commit. With this commit, they pass.
26 lines
706 B
TypeScript
26 lines
706 B
TypeScript
// Type definitions for async-retry 1.2
|
|
// Project: https://github.com/zeit/async-retry#readme
|
|
// Definitions by: Albert Wu <https://github.com/albertywu>
|
|
// Pablo Rodríguez <https://github.com/MeLlamoPablo>
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
|
|
declare function AsyncRetry<A>(
|
|
fn: AsyncRetry.RetryFunction<A>,
|
|
opts: AsyncRetry.Options
|
|
): Promise<A>;
|
|
|
|
declare namespace AsyncRetry {
|
|
interface Options {
|
|
retries?: number;
|
|
factor?: number;
|
|
minTimeout?: number;
|
|
maxTimeout?: number;
|
|
randomize?: boolean;
|
|
onRetry?: (e: Error) => any;
|
|
}
|
|
|
|
type RetryFunction<A> = (bail: (e: Error) => void, attempt: number) => A|Promise<A>;
|
|
}
|
|
|
|
export = AsyncRetry;
|