Skip to content

In JS, bad error message for missing type argument in param tag #26285

Closed
@sandersn

Description

@sandersn
/** @template T */
class CC {
    /** @param {T} t */
    constructor(t) {
    }
}
/** @param {CC} cc */
function foo(cc) {
}

Expected behavior:
Error, something like "Expected 1 type arguments, got 0".

Actual behavior:
Expected CC type arguments; provide these with an '@extends' tag.

The error message has 3 problems:

  1. The error message is intended for classes only (class DD extends CC { ... })
  2. The type isn't quoted.
  3. The expected number of type arguments isn't given.

I think the fix is two-fold:

  1. For parameters, go back to the normal error message.
  2. For classes, give the number of expected type arguments instead of the class name, which is already given. Reading the code, I'm almost certain this is a bug in which the code chooses between multiple messages and then passes them all the same arguments.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions