Skip to main content

isPromise()

isPromise<T>(value): value is Promise<T>

Checks if a value is a Promise or Promise-like object (thenable).


Type Parameters​

T: T = any​

The type of the value the promise resolves to.


Parameters​

value: unknown​

The value to check.


Returns: value is Promise<T>​

true if the value is a Promise or thenable, false otherwise.


Since​

2.0.0


Example​

isPromise(new Promise(() => {})); // => true
isPromise({ then: () => {} }); // => true
isPromise(async () => {}); // => false (it's a function that returns a promise)
isPromise({}); // => false

How it works?​

Type guard that checks if a value is a Promise.

Type Narrowing​

Common Checks​

ValueResult
Promise.resolve(1) true
new Promise(() => {}) true
async () => {} false (function)
(async () => {})() true (called)
{ then: () => {} } false (thenable)

Note​

This checks for native Promise instances. Thenables (objects with .then()) are not detected.


Use Cases​

Detect async operations πŸ“Œβ€‹

Check if a value behaves like a Promise (thenable). Essential for handling mixed synchronous and asynchronous APIs.

if (isPromise(result)) {
await result;
}