Typescript build is failing as it does not seem to like Promise.allSetttled
even though I have set ts config comilerOptions with "lib": [ "ES2020.Promise" ],
It seems as though the response for promise.allSettled
does not include result
or reason
.
When running typescript build I get the following error:
Property 'reason' does not exist on type 'PromiseSettledResult<IMyPromiseResult>'.
and
Property 'value' does not exist on type 'PromiseRejectedResult'.
My code block looks like this and as you can see, I am trying to access reason
and result
from eaech of the promises that get resolved.
const myPromise = async () : Promise<IMyPromiseResult> {
return new Promise((resolve) => {
resolve("hello world")
})
}
const data = await Promise.allSettled([
myPromise()
]);
const response = data.find(res => res.status === 'fulfilled')?.result;
if(!response) {
const error = data.find(res => res.status === 'rejected')?.reason;
throw new Error(error);
}
How can I update the Promise.allSettled declaration to include the correct interfaces?