Skip to content
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

Incorrect type inference in promise.all #35626

Closed
kogemrka opened this issue Dec 11, 2019 · 6 comments
Closed

Incorrect type inference in promise.all #35626

kogemrka opened this issue Dec 11, 2019 · 6 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@kogemrka
Copy link

TypeScript Version: 3.7.x-dev.201xxxxx

Search Terms:

Code

interface A {
    a: number
}

interface B {
    b: number
}

function func(b: B): void {
    console.log(b.b)
}

async function as_a(): Promise<A | undefined> {
    return {a: 10}
}

async function as_b(): Promise<B> {
    return {b: 3}
}

autoExec()

async function autoExec() {
    const [t1, t2] = await Promise.all([as_a(), as_b()])
    func(t2)
}

Expected behavior:
Works correctly in typescript 3.6.4, but failed to compile in typescript@latest and typescript@next with error Argument of type 'B | undefined' is not assignable to parameter of type 'B'.

@matuella
Copy link

Possibly related to #34937

@anton-bot
Copy link

Reproduced in 3.7.2 and 3.7.3.

Works correctly in 3.6.

@anton-bot
Copy link

possible duplicate of #33752

@anton-bot
Copy link

Link to reproduce this - even in nightly builds:

Playground Link

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Dec 18, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.8.1 milestone Dec 18, 2019
@PRR24
Copy link

PRR24 commented Dec 25, 2019

Not sure, if this is the same problem or just related:

class C1 {
    data1: number;
}

class C2 extends C1 {
    data2: number;
}

async test(): Promise<number> {
    let [c2, c1] = await Promise.all([
        Promise.resolve(<C2[]>[new C2()]),
        Promise.resolve(<C1[]>[new C1()]),
    ]);
    return c2[0].data2;
}

-> Error TS2551: Property 'data2' does not exist on type 'C1'. Did you mean 'data1'?

Works correctly with 3.6 but not with 3.7

@rbuckton
Copy link
Member

This may have been fixed by #34501, as it does not seem to occur in TypeScript 3.9 onward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

No branches or pull requests

6 participants