microsoft / microsoft/TypeScript

Misleading error message when forgetting interface body

Open
#44,020 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Help Wanted Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground example and reproduce the diagnostic for the semicolon after the interface extends clause. Trace where the misleading error and the missing-body error are produced, then add or update a regression test covering this exact input. Done means the primary diagnostic identifies the missing interface body without incorrectly suggesting that the generic base interface is invalid.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.