Files
DefinitelyTyped/types/async-retry/index.d.ts
James Ide c122cd24a6 Fix parameterized type inference for async-retry
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.
2018-05-31 20:40:05 -07:00

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;