tsafe
Search
⌃K
Links

isPromiseLike

With this function we can check if its argument is like a Promise. In other words, if its argument has a method that is named then.

Quick example

import { isPromiseLike } from "tsafe/isPromiseLike";
​
const simulateNetworkDelay = new Promise<void>(resolve =>
setTimeout(resolve, 1000)
);
​
const result = isPromiseLike(simulateNetworkDelay);
​
//result === true;

Complementary example

If we have an object that has a method named then:
import { isPromiseLike } from "tsafe/isPromiseLike";
​
const objPromiseLike = {
then: () => null,
x: 3,
y: 4,
};
​
const result = isPromiseLike(objPromiseLike);
​
//result === true;
Last modified 2mo ago