@meld-ts/core
    Preparing search index...

    Function isPromise

    • 检查值是否为 Promise(或符合 TS Promise 接口的 thenable)

      注意:本函数检测的是 TypeScript 的 Promise<T> 类型(需同时具有 thencatch 方法),而非 Promise/A+ 规范的 thenable(后者只需 then)。 因此合法的 A+ thenable { then: fn } 会被判为 false

      安全提示:任何符合此签名的对象都会被判定为 Promise。 下游若对其执行 await.then(),需注意恶意 thenable 可能同步调用回调、 多次调用回调、或永不调用回调。

      Type Parameters

      • T = unknown

      Parameters

      • val: unknown

        — 待检查的任意值

      Returns val is Promise<T>

      true 当且仅当 val 是 Promise 实例或具有 then + catch 方法的 thenable

      if (isPromise(value)) {
      await value;
      }