microsoft / microsoft/TypeScript

Duplicate identifier error when merged interface is declared before class

オープン
#43,088 コメント 1 件 リアクション 1 件 担当者 1 名 GitHub で見る

@sandersn がすでに取り組んでいます。

2021年3月5日 から。

Bug Domain: Binder Rescheduled
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。