Improve the type assertion for is.asyncFunction
This commit is contained in:
parent
af6b03d67f
commit
c25b606c3b
3 changed files with 8 additions and 3 deletions
|
|
@ -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"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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 => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue