Skip to content

promiseTry(fn, ...arg)

使用方法同 Promise.try()

入参

参数类型必填说明
func(...any) => Promise<any>-
argany传递给 func 的参数

示例

ts
import { promiseTry } from "./index";

describe("promiseTry", () => {
  test("normal", () => {
    const reject = (n: number) => Promise.reject(n);
    const rejectSync = () => {
      throw new Error("err");
    };
    promiseTry(reject, 1).catch((x) => {
      expect(x).toBe(1);
    });
    promiseTry(rejectSync).catch((x) => {
      expect(x.message).toBe("err");
    });
  });
});