microsoft / microsoft/TypeScript
JavaScript class property becomes `any` without warning when used in a function that is assigned to itself
未关闭
还没有人认领这个 Issue。
Awaiting More Feedback
Suggestion
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 117
描述
🔎 Search Terms
jsdoc class null any
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
any
⏯ Playground Link
💻 Code
export class Foo {
/**
* @param {number?} maybeNum
*/
constructor(maybeNum) {
this.maybeNum = null;
this.setMaybeNum();
}
setMaybeNum() {
this.maybeNum = Math.max(this.maybeNum);
}
/**
* @param {string} str
*/
takesString(str) {}
foo() {
this.takesString(this.maybeNum);
// ^^^^^^^^^^^^^---- no error, maybeNum is any
}
}
🙁 Actual behavior
this.maybeNum is any
🙂 Expected behavior
this.maybeNum is number | null or (since noImplicitAny is set) an error is emitted warning the user that this.maybeNum is any.
Additional information about the issue
It seems like the core issue here is this line:
this.maybeNum = Math.max(this.maybeNum);
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 TypeScript Playground 示例以及 JavaScript 类中的赋值 this.maybeNum = Math.max(this.maybeNum) 开始。跟踪该赋值如何影响后续的调用 takesString(this.maybeNum),然后根据预期的 number | null 类型或 noImplicitAny 诊断验证修复。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100