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
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);
I think I just realized that undefined has nothing to do with this, but instead that one of the promises' type is a union of different Promise types?
UselessPickles
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.
Mar 4, 2020
@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 Version: 3.8.3 (regression - does not occur in 3.7)
Search Terms: Promise.all return type
Code
Playground Link: http://www.typescriptlang.org/play/index.html#code/CYUwxgNghgTiAEYD2A7AzgF0a4BLDuqUEAXPAEZJIQhQoDcAUI1GgJ4pjwBmArpwVQ8qACgCUZAAowkAW1xoQAHgBuSXMAB88AN6N4B+AHoj8AHJIMIMgAcZ8xQEFEdFJfg2kaNLnIQ28HBo1CoIGEjw-KDcuCggwPqGyOhYdnIKIM4AvPDS6YoAdEEhICIARAAWIBAQSGViTIbYKR72GQBC8DnJeIIoxPAA-LlthcUQoSIAjAAMYvBSoyBFIMETpVEgMXHADcxNyZjwANpBvBAYjgA0gavnGO0Aul3wUADuUPgj+cvEECLHNIOTI3IEdR57RIGEzwACqcQAHjZwFZgPAQDAZDB4FU4GQzhdnAoPF4fH4ApttvEoa8aDAMCICZcCuFYTZkTAAMKsUpiPYAX2YQA
The text was updated successfully, but these errors were encountered: