Skip to content

Unexpected return type of overloaded functionΒ #59251

Closed as not planned
Closed as not planned
@rotu

Description

@rotu

πŸ”Ž Search Terms

overload, multiple call signature

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about overloads

⏯ Playground Link

https://www.typescriptlang.org/play/?target=99&jsx=0&ts=4.8.4&q=5#code/JYOwLgpgTgZghgYwgAgHIHswG8BQz-IAUAHgFzIBG66ANhHCAJTlW30gDceBJ58NAZwjNkYKAFcIXAkTKiJwvnEFTu+XpWp0GI1ts44AvjhwATCAhpwoKAG7XkITKQxgcCdCAFhHmAIIgAJ7IALy+YIRikshwAjFBjMgA9Eny0QCEAPxZOCkyAHqZQA

πŸ’» Code

interface Not{
    (x: boolean): boolean;
    (x: false): true;
    (x: true): false;
    (x: boolean): boolean;
}

declare var not:Not
const notAny = not(true as any) // true !?!?
//    ^?

πŸ™ Actual behavior

The type of notAny is inferred as true, the return type of the second overload call signature.

πŸ™‚ Expected behavior

The type of notAny should infer to boolean, as the first applicable signature without assignment to any (described as the expected behavior here)

Alternately the type of notAny should infer to boolean as the last signature (and thus the type ReturnType<Not>).

Additional information about the issue

Variation of this issue originally reported in #59064.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions