Skip to content

isPromise

function isPromise<T>(value): value is PromiseLike<T>;

Defined in: is-promise.ts:22

Type guard for Promise-like values (thenables). Uses instanceof first (fast path), then duck-typing for non-native thenables.

Narrows both branches: a MaybePromise<T> (T | PromiseLike<T>) becomes PromiseLike<T> when true and T when false, also when T is a type parameter. A T | Promise<T> input keeps Promise<T> in the true branch.

Type Parameter
T
Parameter Type
value MaybePromise<T>

value is PromiseLike<T>

const value: MaybePromise<string> = getData();
if (isPromise(value)) {
const s = await value; // value: PromiseLike<string>, s: string
} else {
value; // string
}