I want to extract all rejected promises. However, even though I filter out the promises that have been rejected, my typescript interpreter still shows that the promises could still be fulfilled. It occurs in the code below
const promises = .... // generate a bunch of promises
const results = await Promise.allSettled(promises)
const errors = results.filter(result => result.status === 'rejected')
// Errors out here -> 'Property 'reason' does not exist on type 'PromiseSettledResult<never>''
const reasons = errors.map(error => error.reason)
Why does it show this Property 'reason' does not exist on type 'PromiseSettledResult<never>'. error even though I have filtered the list to make sure it only contains rejected promise? How can I fix this?