镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Incorrect type inference in promise.all #35626

Description

@kogemrka

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

Activity

  1. matuella commented on Dec 12, 2019

    @matuella

    Possibly related to #34937

  2. anton-bot commented on Dec 18, 2019

    @anton-bot

    Reproduced in 3.7.2 and 3.7.3.

    Works correctly in 3.6.

  3. anton-bot commented on Dec 18, 2019

    @anton-bot

    possible duplicate of #33752

  4. anton-bot commented on Dec 18, 2019

    @anton-bot

    Link to reproduce this - even in nightly builds:

    Playground Link

  5. PRR24 commented on Dec 25, 2019

    @PRR24

    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

  6. rbuckton commented on Oct 31, 2020

    @rbuckton
    Contributor

    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

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions