isPromiseLike
Checks if a value is a thenable (has a .then() method).
Looser than isPromise: accepts any object or function with a then
method, including non-standard Promise implementations without .catch().
Follows the Promise/A+ specification for thenables.
Available since v2.0.3
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
Section titled “Returns”value is PromiseLike<unknown> — true if value is a PromiseLike (thenable)
Examples
Section titled “Examples”Detect any thenable
Section titled “Detect any thenable”Returns true for native Promises and any object with a .then() method.
Handle both Promises and thenables in a utility
Section titled “Handle both Promises and thenables in a utility”Use isPromiseLike to accept any thenable, not just native Promises.
