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)checkmark true
new Promise(() => {})checkmark true
async () => {}cross false (function)
(async () => {})()checkmark true (called)
{ then: () => {} }cross 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;
}