Skip to content

isPromise

Checks if a value is a Promise or a thenable.

Returns true for any object that has .then() and .catch() methods, including native Promises and userland implementations.

Available since v2.0.0

import { isPromise } from '@helpers4/type';
isPromise(value: unknown): value is PromiseLike<unknown>
ParameterTypeDescription
valueunknownThe value to check

value is PromiseLike<unknown> — True if value is a Promise-like object

isPromise(Promise.resolve(42))     // => true
isPromise(new Promise(() => {}))   // => true
isPromise({ then: () => {} })      // => false (no .catch)
isPromise(42)                      // => false

View source on GitHub