$ gnpm install is-actual-promise
Similar to p-is-promise
and
is-promise
, which are also both
fine alternatives to this.
Differences (ie, "why this thing then?")
is-promise
is hybrid, but p-is-promise
is ESM-only.Promise
interface, not just PromiseLike
(ie, it also
asserts .catch()
and .finally()
. (p-is-promise
tests for
.catch()
, neither tests for .finally()
.)Promise<any | void>
.(Note that this module does not verify that the .catch()
,
.then()
, and .finally()
methods return Promises, because that
is impossible at run-time without actually calling them. No
duck-typing method should ever be considered fully
authoritative.)
import { isPromise } from 'is-actual-promise'
console.log(isPromise(new Promise(() => {}))) // true
console.log(isPromise((async () => true)())) // true
console.log(isPromise(Promise.resolve(true))) // true
console.log(isPromise({
then: async () => 5,
finally: async () => {},
catch: () => {},
})) // true, but not accurate, limitation of duck typing
Copyright 2013 - present © cnpmjs.org | Home |