Skip to content

Commit

Permalink
Improve the type assertion for is.asyncFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 7, 2019
1 parent af6b03d commit c25b606
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
3 changes: 1 addition & 2 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ is.promise = (value: unknown): value is Promise<unknown> => is.nativePromise(val

is.generatorFunction = isObjectOfType<GeneratorFunction>(TypeName.GeneratorFunction);

// eslint-disable-next-line @typescript-eslint/ban-types
is.asyncFunction = isObjectOfType<Function>(TypeName.AsyncFunction);
is.asyncFunction = (value: unknown): value is ((...args: any[]) => Promise<unknown>) => 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');
Expand Down
6 changes: 6 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit c25b606

Please sign in to comment.