Vinyl
    Preparing search index...

    Function isPromiseLike

    • Determines whether a value implements the PromiseLike<T> interface.

      This function checks if the given value is a non-null object with a then method, which is the structural requirement for PromiseLike in TypeScript.

      Type Parameters

      • T = any

        The type the promise resolves to (optional, used for type narrowing).

      Parameters

      • value: unknown

        The value to check.

      Returns value is PromiseLike<T>

      true if the value is PromiseLike<T>, otherwise false.

      const maybePromise: unknown = Promise.resolve(42)
      if (isPromiseLike(maybePromise)) {
      maybePromise.then(value => console.log(value)) // value is type-safe
      }