Skip to content

Complain expected when assigning Promise<A | B> to Promise<A> #16202

@dggluz

Description

@dggluz

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)

Code

// This fails as number is not assignable to string
let strOrNum: string | number;
let str: string = strOrNum;

// This fails for the same reason
let strOrNumA: Array<string | number>
let strA: Array<string> = strOrNumA;

// This works, and I think it shouldn't
let strOrNumP: Promise<string | number>
let strP: Promise<string> = strOrNumP;

Expected behavior:
Expected TypeScript to complain about the assignment of strP (as it does with strA).

Actual behavior:
TypeScript doesn't complain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions