microsoft / microsoft/TypeScript
Misleading error message when forgetting interface body
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
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.

コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の例から始め、interface extends 句の後にあるセミコロンに対する診断を再現します。誤解を招くエラーと本体がないことを示すエラーがどこで生成されるかを追跡し、その後、この入力を正確に対象とするリグレッションテストを追加または更新します。完了条件は、主診断がインターフェイス本体の欠落を示し、ジェネリックな基底インターフェイスが無効であると誤って示唆しないことです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100