microsoft / microsoft/TypeScript

JSDoc comment on JS class property isn't inherited when derived class also initializes it

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

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

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

説明

Bug Report

When a JS class extends another, and members are overridden in the constructor, they will lose all of their documentation - even if they are compatible values.

🔎 Search Terms

jsdoc class es6 js extends

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

Playground link with relevant code

Note the type info when hovering over this.a in Derived's constructor, or a in the bottom line.

💻 Code
class Base
{
    constructor()
    {
        /** I am an integer! */
        this.a = 100;
    }
}

class Derived extends Base
{
    constructor()
    {
        super();

        this.a = 50;

// hover over this.a above to see the issue
    }
}

// hover over a to see the issue as well
new Derived().a
🙁 Actual behavior

a was overridden by Derived, even though it is a type match.

🙂 Expected behavior

While I can see the usefulness here if a was a different/incompatible type entirely, I would rather an error occur on, for instance, this.a = "str"; because a is a number, not a string, and for it to inherit the JSDoc properly. It seems like this.xxx in a constructor declares a new variable, even if it inherits one.

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

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

はじめの一歩

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

調査の方向性

リンクされた TypeScript Playground から始め、Derivedthis.anew Derived().a に対するホバー動作を再現してください。JavaScript のクラスコンストラクターと JSDoc コメントがどのように解釈されるかを追跡し、互換性のあるオーバーライドではドキュメントが保持され、互換性のない代入が診断されることを確認してください。

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

評価

技術スタック
javascript, typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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