microsoft / microsoft/TypeScript

Duplicate identifier error when merged interface is declared before class

Abierto
#43,088 1 comentario 1 reacción 1 asignado Ver en GitHub

@sandersn ya está trabajando en esto.

Desde el 5/3/2021.

Bug Domain: Binder Rescheduled
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.