microsoft / microsoft/TypeScript

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

Offen
#44,587 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Experience Enhancement Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem verlinkten TypeScript Playground und reproduziere das Hover-Verhalten für this.a in Derived und new Derived().a. Verfolge, wie die JavaScript-Klassenkonstruktoren und der JSDoc-Kommentar interpretiert werden, und überprüfe anschließend, dass kompatible Überschreibungen die Dokumentation beibehalten und inkompatible Zuweisungen diagnostiziert werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.