📜  承诺所有已解决的打字稿代码示例

📅  最后修改于: 2022-03-11 14:48:37.461000             🧑  作者: Mango

代码示例2
const myPromise = async (): Promise => {
  return new Promise((resolve) => {
    resolve("hello world");
  });
};

const data = await Promise.allSettled([myPromise()]);

const response = (data.find(
  (res) => res.status === "fulfilled"
) as PromiseFulfilledResult | undefined)?.value;

if (!response) {
  const error = (data.find(
    (res) => res.status === "rejected"
  ) as PromiseRejectedResult | undefined)?.reason;
  throw new Error(error);
}