You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Promise.all return type incorrect when some promise types are unions of Promise types, rather than Promise of union of types. #37216
TypeScript Version: 3.8.3 (regression - does not occur in 3.7)
Search Terms: Promise.all return type
Code
declareconstconditional: boolean;asyncfunctionfoo(): Promise<void>{// Note: promiseA cannot possibly resolve to undefinedconstpromiseA=Promise.resolve("hello");constpromiseB=conditional ? Promise.resolve(10) : Promise.resolve(undefined);const[resultA,resultB]=awaitPromise.all([promiseA,promiseB]);// Unexpected error here: resultA is possibly undefinedalert(resultA.toUpperCase());}```**Expected behavior:**Type of `resultA` should be `string`;**Actual behavior:**Type of `resultA` is `string|undefined`;**Workaround:**Tack on a `asconst` to the tuple of promises being passed to `Promise.all()`:```tsconst[resultA,resultB]=awaitPromise.all([promiseA,promiseB]asconst);
changed the title [-]Promise.all return type incorrect when some promises may resolve to undefined[/-][+]Promise.all return type incorrect when some promise types are unions of Promise types, rather than Promise of union of types.[/+]on Mar 4, 2020
Nicholai Main (@nmain) Thanks. I don't know what's wrong with my eyes. Looking at the search results again it seems obvious that those were likely duplicates I should have looked at.
Activity
UselessPickles commentedon Mar 4, 2020
I think I just realized that
undefinedhas nothing to do with this, but instead that one of the promises' type is a union of different Promise types?[-]Promise.all return type incorrect when some promises may resolve to undefined[/-][+]Promise.all return type incorrect when some promise types are unions of Promise types, rather than Promise of union of types.[/+]nmain commentedon Mar 4, 2020
Probable duplicate of #35626
Probable duplicate of #34937
Probable duplicate of #33562
I think these all trace back to #33057, which is my fault, so I am sorry.
UselessPickles commentedon Mar 4, 2020
Nicholai Main (@nmain) Thanks. I don't know what's wrong with my eyes. Looking at the search results again it seems obvious that those were likely duplicates I should have looked at.
typescript-bot commentedon Mar 7, 2020
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.