Skip to content

Method overloads are not inherited from implemented interfacesΒ #56909

Closed as not planned
@jeengbe

Description

@jeengbe

πŸ”Ž Search Terms

method function overload interface intheritance

πŸ•— Version & Regression Information

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

⏯ Playground Link

https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgJLIN4Chm+TEACgGcwoAuZAIjioEpKA3Ae2ABMBuHPAksyqgCN6TVpywBfLFgQAbOMWLIAwsmABbAA6yI6iOCXpsefEVIVk50AHMGyFu0xSpWNhDlwoKBMxClkCJTKXDIAdARYAPSRyAB6APxRMQDKABbMAK6ybMiCKHwWNCL2YsgA7sBgqcgA1ACMyMyM0LLMcGxAA

πŸ’» Code

interface I {
    fn(str: "a"): void;
    fn(str: "b"): void;
}

class C implements I {
    fn(str: string): void {}
}

declare const c: C;

c.fn
// ^?
// Should be (str: "a"): void with +1 overload

πŸ™ Actual behavior

Both signatures for fn declared in I should be inherited by C, and the generic implementation that takes str: string should not be considered the primary signature. Instead, the signatures fn(str: "a"): void and fn(str: "b"): void should come from the interface.

This would also make sense when implementing several interfaces with different signatures for the same function, you wouldn't only want to get the merged function in the end there.

πŸ™‚ Expected behavior

see above.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions