Closed
Description
TypeScript Version: 3.8.3 (regression - does not occur in 3.7)
Search Terms: Promise.all return type
Code
declare const conditional: boolean;
async function foo(): Promise<void> {
// Note: promiseA cannot possibly resolve to undefined
const promiseA = Promise.resolve("hello");
const promiseB = conditional ? Promise.resolve(10) : Promise.resolve(undefined);
const [resultA, resultB] = await Promise.all([promiseA, promiseB]);
// Unexpected error here: resultA is possibly undefined
alert(resultA.toUpperCase());
}```
**Expected behavior:**
Type of `resultA` should be `string`;
**Actual behavior:**
Type of `resultA` is `string | undefined`;
**Workaround:**
Tack on a `as const` to the tuple of promises being passed to `Promise.all()`:
```ts
const [resultA, resultB] = await Promise.all([promiseA, promiseB] as const);