microsoft / microsoft/TypeScript

TS2377 not reported when 'super' is called conditionally

オープン
#45,377 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Domain: classes
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Bug Report

The TS2377 error is reported when the constructor of a derived class does not contain a call to 'super'. However, it is not reported when only some branches contain the call but not others.

🔎 Search Terms

TS2377 super class missing branch

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

Playground link with relevant code

💻 Code
class CustomError extends Error {
  constructor(value: string | number) {
    if (typeof value === 'string') {
      super(value)
    } else {
      // oops, no super() call!
    }
  }
}
🙁 Actual behavior

TypeScript does not report any errors for the above code.

🙂 Expected behavior

TypeScript should report TS2377 for the above code, since 'super' isn't called in every branch.

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

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

はじめの一歩

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

調査の方向性

リンクされた Playground の例から始め、条件分岐がすべて super を呼び出していない場合に欠落している TS2377 診断を確認します。次に、派生クラスのコンストラクターと制御フロー分岐を TypeScript コンパイラーがどのように処理するかを追跡し、すべての分岐が super を呼び出さない限り TS2377 が報告されることを示すカバレッジを追加します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
48/100

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

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