From c25b606c3bda79f82fbe506e1c3b1116c3e0eaef Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 7 Nov 2019 16:28:20 +0700 Subject: [PATCH] Improve the type assertion for `is.asyncFunction` --- package.json | 2 +- source/index.ts | 3 +-- test/test.ts | 6 ++++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1ffa0e6..1bb1f91 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "rxjs": "^6.4.0", "tempy": "^0.3.0", "ts-node": "^8.3.0", - "typescript": "^3.4.1", + "typescript": "^3.7.2", "xo": "^0.25.3", "zen-observable": "^0.8.8" }, diff --git a/source/index.ts b/source/index.ts index 2cfe2c3..90ca4c6 100644 --- a/source/index.ts +++ b/source/index.ts @@ -152,8 +152,7 @@ is.promise = (value: unknown): value is Promise => is.nativePromise(val is.generatorFunction = isObjectOfType(TypeName.GeneratorFunction); -// eslint-disable-next-line @typescript-eslint/ban-types -is.asyncFunction = isObjectOfType(TypeName.AsyncFunction); +is.asyncFunction = (value: unknown): value is ((...args: any[]) => Promise) => getObjectType(value) === TypeName.AsyncFunction; // eslint-disable-next-line no-prototype-builtins, @typescript-eslint/ban-types is.boundFunction = (value: unknown): value is Function => is.function_(value) && !value.hasOwnProperty('prototype'); diff --git a/test/test.ts b/test/test.ts index cbf59b0..0d9c13a 100644 --- a/test/test.ts +++ b/test/test.ts @@ -560,6 +560,12 @@ test('is.promise', t => { test('is.asyncFunction', t => { testType(t, 'asyncFunction', ['function']); + + const fixture = async () => {}; + if (is.asyncFunction(fixture)) { + // eslint-disable-next-line promise/prefer-await-to-then + t.true(is.function_(fixture().then)); + } }); test('is.generator', t => {