Skip to content

Compiler gives two different errors for wrong number of type arguments #19374

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

Open
sandersn opened this issue Oct 20, 2017 · 3 comments
Open
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging
Milestone

Comments

@sandersn
Copy link
Member

sandersn commented Oct 20, 2017

class B<T, U = number> {
    t: T
    u: U
}
class D extends B<string, string, string> {
                ~
                Generic type B<T, U> requires between 1 and 2 type arguments.
    d: number
}
let b = new B<string, string, string>()
        ~~~
        Expected 1-2 type arguments, but got 3.

Expected behavior:
You get a wordier, less helpful message when incorrectly extending a base class. You get a terser, more detailed, message when incorrectly creating an instance of the base class.

Actual behavior:
Both messages should be the new terse, detailed message. I forgot to change this when I added the new message.

@ahejlsberg
Copy link
Member

I'm not a great fan of the terse message because you can't tell which type is in question without examining the source code. The longer message is more informative when you're just looking at a list of errors.

@sandersn
Copy link
Member Author

What about adding the type name? 'B<T, U>' expected 1-2 type arguments, but got 3.

@ahejlsberg
Copy link
Member

ahejlsberg commented Oct 20, 2017

I'd prefer something simpler, like Too many type arguments were specified for type 'B<T, U>'. And, in the opposite case Too few type arguments were specified for type 'B<T, U>'. I don't really care about the actual number and possible range, I actually find that to be noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging
Projects
None yet
Development

No branches or pull requests

3 participants