microsoft / microsoft/TypeScript

Duplicate identifier error when merged interface is declared before class

Offen
#43,088 1 Kommentar 1 Reaktion 1 zugewiesene Person Auf GitHub ansehen

@sandersn arbeitet bereits daran.

Seit 05.3.2021.

Bug Domain: Binder Rescheduled
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Bug Report

🔎 Search Terms

interface accessors getters declaration merge

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about interfaces, merging, and getters
⏯ Playground Link

Playground link

💻 Code
class Foo {
    get x(): number { return 0; } // ok
}
interface Foo {
    x: number; // ok
}

interface Bar {
    x: number; // not ok
}
class Bar {
    get x(): number { return 0; } // not ok
}
🙁 Actual behavior

Bar throws an error but not Foo

🙂 Expected behavior

Neither or both throw an error (probably both).

While exploring whether an interface can merge with a class in order to narrow the type of a class's inherited getter (there is no documentation, but the answer seems to be that accessor properties are not properly representable in interfaces as of 4.2.2), I came across seemingly unpredictable conditions for what tsc would accept. Eventually, it became apparent that the order of the interface and class declarations has bearing on whether an error is thrown.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.