microsoft / microsoft/TypeScript
JSDoc comment on JS class property isn't inherited when derived class also initializes it
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par le TypeScript Playground lié et reproduisez le comportement au survol pour this.a dans Derived et new Derived().a. Suivez la manière dont les constructeurs de classes JavaScript et le commentaire JSDoc sont interprétés, puis vérifiez que les redéfinitions compatibles conservent la documentation et que les affectations incompatibles sont diagnostiquées.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, typescript
- Domaine
- compilers
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100