📅  最后修改于: 2022-03-11 14:48:37.461000             🧑  作者: Mango
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);
}