Skip to content

String literal type inconsistency in overload resolution #9443

@zhuravlikjb

Description

@zhuravlikjb

As far as I see, the TS compiler still sees a string literal type of a single literal as an old style "string parameter" thing. I thought that the concept of string literal types should replace overloading on string parameters, but seems that it doesn't.

That complicates things, and results in a "strange" behaviour in overload resolution:

class A256 {
    m(a): any;
    m(a: "a" | "b"): string;
    m(a: "c"): string;
    m(a): any {}
}

var foo1 = new A256().m("a"); // 'any'
var foo2 = new A256().m("c"); // 'string'

What should be the correct logic with string literal types in overload resolution?
Shouldn't overloads with unions of literals precede the others as well, when resolving overloads?

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions