microsoft / microsoft/TypeScript
Misleading error message when forgetting interface body
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
Bug Report
🔎 Search Terms
"An interface can only extend an identifier/qualified-name with optional type arguments", interface, body
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about the error message.
⏯ Playground Link
Playground link with relevant code
💻 Code
The following code tries to declare an interface Derived<T> deriving from Base1<T> and Base2<T> without any extra members. I forgot to type the empty interface body {}, instead typing a semicolon.
interface Base1<T> {
method1(value: T): void;
}
interface Base2<T> {
method2(value: T): void;
}
// Missing {} at the end of the following line.
interface Derived<T> extends Base1<T>, Base2<T>;
🙁 Actual behavior
In the last line of code, I get the following error:
An interface can only extend an identifier/qualified-name with optional type arguments. (2499)
The error doesn't address the actual problem (the missing braces). Instead, it reads as if there was something wrong with deriving from Base2<T>. I actually took it to mean that I cannot derive from a generic interface, so I spent time trying to find out more about this (non-existing) limitation.
🙂 Expected behavior
Instead of the misleading error message, I'd expect to get an error telling me that the curly braces are missing.
To be fair, this error does show, but not always: If there is a line break after the last line, the correct error will show on the first character of the following empty line (see screenshot). But this is nearly invisible next to the big red (wrong) error above.

Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem verlinkten TypeScript Playground-Beispiel und reproduziere die Diagnose für das Semikolon nach der interface extends-Klausel. Verfolge, wo der irreführende Fehler und der Fehler wegen des fehlenden Bodys erzeugt werden, und füge dann einen Regressionstest hinzu oder aktualisiere ihn, der genau diese Eingabe abdeckt. Erledigt ist die Aufgabe, wenn die primäre Diagnose den fehlenden Interface-Body identifiziert, ohne fälschlicherweise nahezulegen, dass das generische Basis-Interface ungültig ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100