Skip to content

Promise.all types inferred incorrectly #36232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
clurdish opened this issue Jan 16, 2020 · 2 comments
Closed

Promise.all types inferred incorrectly #36232

clurdish opened this issue Jan 16, 2020 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@clurdish
Copy link

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+.

@MartinJohns
Copy link
Contributor

Duplicate of #35626, #34937, and several others.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Jan 18, 2020
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants