Value is promise-like
JavaScript, Type, Function, Promise · Oct 20, 2020

Checks if an object looks like a Promise
.
- Check if the object is not
null
, itstypeof
matches eitherobject
orfunction
and if it has a.then
property, which is also afunction
.
const isPromiseLike = obj =>
obj !== null &&
(typeof obj === 'object' || typeof obj === 'function') &&
typeof obj.then === 'function';
isPromiseLike({
then: function() {
return '';
}
}); // true
isPromiseLike(null); // false
isPromiseLike({}); // false