microsoft / microsoft/TypeScript
Duplicate identifier error when merged interface is declared before class
@sandersn ci sta già lavorando.
Dal 5/3/2021.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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
💻 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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.