Skip to content

Type inference issue with overload signatures and string literal types #15086

Closed
@marcomura

Description

@marcomura

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

Code

interface Base {
    key: string;
}
interface A extends Base {
}
interface B extends Base {
}

export function test(key: "aa"): A;
export function test(key: "bb1"): B;
export function test(key: "bb2"): B;

export function test(key: string): Base {
    return { key: key };
}

export function bbTest(key: "bb1" | "bb2"): B {
    return test(key);
}

playground url:
here

Expected behavior:
No compiler errors; type inference to understand that "return test(key)" returns a B type.

Actual behavior:
"return test(key)" doesn't compile because of an argument type error

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