TypeScript · Middle · Question 64 of 75

How do you narrow the results of Promise.allSettled?

const results = await Promise.allSettled(tasks);
const values = results.filter((r) => r.status === 'fulfilled').map((r) => r.value);

Explanation

PromiseSettledResult<T> is a discriminated union of fulfilled (value) and rejected (reason) results.

Further reading

Problem with a question

TypeScript · Middle · question 64

Test yourself

Take the TypeScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz