tsafe
GitHub
  • 👋What is tsafe?
  • ⚙️How to import
  • assert
  • Equals
  • id
  • is
  • objectKeys
  • exclude
  • isAmong
  • symToStr
  • ReturnType
  • Parameters
  • Param0
  • typeGuard
  • capitalize/uncapitalize
  • MethodNames
  • isPromiseLike
  • flip
  • objectEntries
  • objectFromEntries
  • UnionToIntersection
  • 🚧withDefaults
  • 📉UnpackPromise
Powered by GitBook
On this page
  • Quick example
  • Complementary example

Was this helpful?

Edit on GitHub

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;
PreviousMethodNamesNextflip

Last updated 5 months ago

Was this helpful?