microsoft / microsoft/TypeScript

Misleading error message for `super.instanceProperty`

オープン
#55,883 コメント 6 件 リアクション 7 件 担当者 0 名 GitHub で見る

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

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

説明

Take the following code:

export abstract class YaddaBase {
    protected roots = "hi";
}

export class DerivedYadda extends YaddaBase {
    public get rootTests() {
        return super.roots;
    }
}

TypeScript nightly (5.3.0-dev.20230926) reports:

Class field 'roots' defined by the parent class is not accessible in the child class via super.

The error message here is confusing - one might believe that this has to do with accessing a member with a protected modifier, but it is really about accessing an instance field with super. A better error message would be:

'roots' is defined as an instance property and must be accessed through 'this', not 'super'.

We can also provide a quick fix for this error message.

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

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

はじめの一歩

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

調査の方向性

TypeScript のスニペットで診断を再現し、報告されたメッセージがどこで定義されているかを調査します。診断が、インスタンスプロパティには super ではなく this を介してアクセスする必要があることを明確に説明し、提案された quick fix を issue の一部として評価できれば完了です。

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

評価

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

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

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