Skip to content

When subclassing incorrectly, the compiler error suggests changing base class rather than the derived one #61407

@parzhitsky

Description

@parzhitsky

🔎 Search Terms

override method compiler error confusing message Target signature too few

🕗 Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEkoGdnwGIHtPwN4Ch4j4BbEAFwAtNgAKASgC54A3TAS2HwF999QkcRNFTwAQrHggAHuRAA7YGiw4CxeJhYgYMTgjJUatWAHNm8gK4kARtqasOXXkA

💻 Code

declare class Foo {
    method(): void
}

declare class Bar extends Foo {
    override method(arg: number): void
    //       ~~~~~~
    // Error! Target signature provides too few arguments. Expected 1 or more, but got 0.
}

🙁 Actual behavior

An error message explains how base class has less arguments than expected

🙂 Expected behavior

An error message explains how derived class has more arguments than expected

Additional information about the issue

I understand that the compiler can't know whether the base class or the derived class is defined incorrectly. But:

  • normally, deriving from a class means that the developer wants to encapsulate the scope of work within this class and avoid changing the base class; also
  • seeing an error related to base class on a method of the derived class is unexpected and confusing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions