Settle a Tuple of Promises, Typed per Element
Write the code, see it run, pass the checks.
The problem
- hard
- Code
- Pro
Without using Promise.allSettled, write settleAll(promises): wait for every promise in the array to settle and resolve, never reject, with an array of results in the same order: an object with status fulfilled and the value, or status rejected and the reason. Export that result as a type Settled<T>, a union told apart by status, with reason typed unknown. Type settleAll so a tuple of promises gives a tuple of results, each typed by its own promise's value, and values that aren't promises are rejected.
Your code must pass
- Reports each promise's outcome in order
- Never rejects
- Returns an empty array for no promises
- Has no type errors
- Types each result by its own promise
- Narrows each result by status
- Rejects values that aren't promises