Skip to content

Promise.all types inferred incorrectly #36232

Closed
@clurdish

Description

@clurdish

TypeScript Version: 3.8.0-dev.20200115

Search Terms: Promise.all

Code

interface A {
    id: string
}

interface B {
    id: string
    fieldB: string
}

async function countEverything(): Promise<number> {
    const providerA = async (): Promise<A[]> => { return [] }
    const providerB = async (): Promise<B[]> => { return [] }

    const [resultA, resultB] = await Promise.all([
        providerA(),
        providerB(),
    ]);

    const dataA: A[] = resultA;
    const dataB: B[] = resultB;
    if (dataA && dataB) {
        return dataA.length + dataB.length;
    }
    return 0;
}

Expected behavior:
Compiles without errors.

Actual behavior:
Compile fails.

Type 'A[]' is not assignable to type 'B[]'.
  Property 'fieldB' is missing in type 'A' but required in type 'B'.(2322)
input.ts(7, 5): 'fieldB' is declared here.

Playground Link: Playground Link

Related Issues: #16017

This appears to be the exact same issue as #16017, just reappearing in version 3.7+.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions