想用Promise.allSettled
,但又不想升级tsconfog.json下的lib
属性,可以这样模拟:
const allSettled = async (promises: Promise<any>[]) => {
const p2 = promises.map((promise) => promise.then((value) => ({
status: 'fulfilled',
value,
}), (reason) => ({
status: 'rejected',
reason,
})));
const results = await Promise.all(p2);
return results;
};