From c122cd24a649fe9bc80d1a37ad645b9e43710d3b Mon Sep 17 00:00:00 2001 From: James Ide Date: Thu, 31 May 2018 20:40:05 -0700 Subject: [PATCH] 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. --- types/async-retry/async-retry-tests.ts | 4 ++-- types/async-retry/index.d.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/types/async-retry/async-retry-tests.ts b/types/async-retry/async-retry-tests.ts index 68327b66bd..20dfc62c4b 100644 --- a/types/async-retry/async-retry-tests.ts +++ b/types/async-retry/async-retry-tests.ts @@ -10,12 +10,12 @@ const o: Options = { onRetry: (e: Error) => 42 }; -retry( +const hello: Promise = retry( bail => 'hello', { retries: 3 } ); -retry( +const answer: Promise = retry( bail => Promise.resolve(42), { retries: 3 } ); diff --git a/types/async-retry/index.d.ts b/types/async-retry/index.d.ts index a2f65e00a4..6b50c71b63 100644 --- a/types/async-retry/index.d.ts +++ b/types/async-retry/index.d.ts @@ -19,7 +19,7 @@ declare namespace AsyncRetry { onRetry?: (e: Error) => any; } - type RetryFunction = (bail: (e: Error) => A, attempt: number) => A|Promise; + type RetryFunction = (bail: (e: Error) => void, attempt: number) => A|Promise; } export = AsyncRetry;