microsoft / microsoft/TypeScript
JSDoc comment on JS class property isn't inherited when derived class also initializes it
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con il TypeScript Playground collegato e riproduci il comportamento al passaggio del mouse su this.a in Derived e new Derived().a. Traccia come vengono interpretati i costruttori delle classi JavaScript e il commento JSDoc, quindi verifica che gli override compatibili mantengano la documentazione e che le assegnazioni incompatibili vengano diagnosticate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100