-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Promise.all sometimes infers incorrect types #52601
Copy link
Copy link
Closed as not planned
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options
Description
Bug Report
🔎 Search Terms
Promise.all, Awaited
🕗 Version & Regression Information
4.9.5
⏯ Playground Link
I couldn't repro this bug in the playground.
Please see this test repo instead.
💻 Code
Multiple files are needed to repro this bug. See the test repo. The relevant error is:
export async function testPromiseAll(docs: string[]) {
const requests = docs.map(async doc => fetch("/doc"));
const responses = await Promise.all(requests);
for (const res of responses) {
await res.blob(); // Property 'blob' does not exist on type 'Promise<Response>'.
}
}🙁 Actual behavior
Code fails to build with:
Property 'blob' does not exist on type 'Promise<Response>'.
This is because the return type of Promise.all() becomes a Promise<Array<Promise<Response>>> instead of a Promise<Array<Response>>.
🙂 Expected behavior
Code typechecks.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options