chore(shared): improve isPromise check in accordance with Promise A+ specification (#8506)

This commit is contained in:
丶远方 2023-07-11 17:41:09 +08:00 committed by GitHub
parent 736cf154cc
commit 97b6fae6b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -50,7 +50,11 @@ export const isObject = (val: unknown): val is Record<any, any> =>
val !== null && typeof val === 'object'
export const isPromise = <T = any>(val: unknown): val is Promise<T> => {
return isObject(val) && isFunction(val.then) && isFunction(val.catch)
return (
(isObject(val) || isFunction(val)) &&
isFunction(val.then) &&
isFunction(val.catch)
)
}
export const objectToString = Object.prototype.toString