Determines whether a value implements the PromiseLike<T> interface.
PromiseLike<T>
This function checks if the given value is a non-null object with a then method, which is the structural requirement for PromiseLike in TypeScript.
then
PromiseLike
The type the promise resolves to (optional, used for type narrowing).
The value to check.
true if the value is PromiseLike<T>, otherwise false.
true
false
const maybePromise: unknown = Promise.resolve(42)if (isPromiseLike(maybePromise)) { maybePromise.then(value => console.log(value)) // value is type-safe} Copy
const maybePromise: unknown = Promise.resolve(42)if (isPromiseLike(maybePromise)) { maybePromise.then(value => console.log(value)) // value is type-safe}
Determines whether a value implements the
PromiseLike<T>interface.This function checks if the given value is a non-null object with a
thenmethod, which is the structural requirement forPromiseLikein TypeScript.