microsoft / microsoft/TypeScript

Misleading error message when forgetting interface body

Ouverte
#44,020 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Experience Enhancement Help Wanted Suggestion
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

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.

image

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par l’exemple TypeScript Playground lié et reproduisez le diagnostic pour le point-virgule après la clause interface extends. Suivez l’origine de l’erreur trompeuse et de l’erreur de corps manquant, puis ajoutez ou mettez à jour un test de régression couvrant exactement cette entrée. Le travail est terminé lorsque le diagnostic principal identifie le corps d’interface manquant sans suggérer à tort que l’interface de base générique est invalide.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
compilers
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.