Skip to content

more accurate error message when derived class has different constructor signature #31046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
MhMadHamster opened this issue Apr 20, 2019 · 1 comment · Fixed by #40073
Closed
5 tasks done
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Fixed A PR has been merged for this issue

Comments

@MhMadHamster
Copy link

Search Terms

abstract derived class constructor signature error message

Suggestion

Currently the following code:

abstract class A { }

class B extends A {
    constructor(a: string) {
        super();
    }
}

const b: typeof A = B;

will give you the following error: Type 'typeof B' is not assignable to type 'typeof A'.

When you encountering this issue for the first time as a new typescript user, and you already have a bunch of code for both abstract and derived classes, it might be hard to track down what is causing the type error. So consider adding more specificity to the error message, smth like "Derived class should have the same constructor signature as a parent".

Use Cases

Currently error message is not clear enough.

Examples

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@DanielRosenwasser
Copy link
Member

Thanks @a-tarasyuk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Fixed A PR has been merged for this issue
Projects
None yet
4 participants