To fix the "Property ‘allSettled’ does not exist on type ‘PromiseConstructor’.ts(2339)" error with TypeScript, we can add the allSettled
method to the PromiseConstructor
type definition.
For instance, we write
declare interface PromiseConstructor {
allSettled(
promises: Array<Promise<any>>
): Promise<
Array<{ status: "fulfilled" | "rejected"; value?: any; reason?: any }>
>;
}
to add the allSettled
method into the PromiseConstructor
interface.
We add the parameter with promises: Array<Promise<any>>
.
And the return type is Promise< Array<{ status: "fulfilled" | "rejected"; value?: any; reason?: any }>
.
Now we can use Promise.allSettled
without compiler errors.