microsoft / microsoft/TypeScript
TypeScript doesn't error on late definition/initialization of variables from outside an async closure.
未关闭
还没有人认领这个 Issue。
Awaiting More Feedback
Suggestion
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
TypeScript Version: 4.0-beta and Nightly (as of writing)
Search Terms: async closure variable initialization
Code
async function doSomething(): Promise<void> {
const x = setTimeout(() => {
const a = someVar + 1;
}, 5000)
await doSomethingSlowly();
const someVar = 5;
}
Expected behavior:
There should be an error on const a = someVar + 1; since someVar may not have been initialized.
Actual behavior:
No error/warning with any settings that I could find.
Playground Link: link
Related Issues:
Comments
I see folks hit this every so often and it feels like something the TypeScript compiler could help warn against, in a similar way that 2448 and 2454 error.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从提供的 TypeScript Playground 复现开始,并将其行为与相关诊断 2448 和 2454 进行比较。确定编译器是否能够可靠地报告 someVar 可能在 async closure 中未初始化,然后根据示例和现有的相关案例验证任何诊断结果。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100