Skip to content

Promise.all sometimes infers incorrect types #52601

@JavaScriptBach

Description

@JavaScriptBach

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions