microsoft / microsoft/TypeScript
JSDoc comment on JS class property isn't inherited when derived class also initializes it
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 TypeScript Playground 开始,复现 Derived 中 this.a 和 new Derived().a 的悬停行为。跟踪 JavaScript 类构造函数和 JSDoc 注释的解释方式,然后验证兼容的覆盖会保留文档,而不兼容的赋值会被诊断。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100