microsoft / microsoft/TypeScript
Why doesn't awaiting a Promise<never> change reachability?
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
TypeScript Version: 3.7.2
Search Terms:
- "Promise"
await- reachability analysis
- control flow analysis
- definite assignment analysis
Code
(async () => {
let b: string;
let a1 = await Promise.reject(); // returns Promise<never>
b = ""; // Not unreachable?
b.toUpperCase(); // Not unreachable?
})();
Expected behavior:
As a1 is inferred to be never (e.g. behaves like in the non-promised version), I expected the rest of the code to be marked as unreachable aswell:
function returnNever(): never { throw new Error(); }
(async () => {
let b: string;
let a0 = returnNever(); // a0 is never
b = ""; // Unreachable
b.toUpperCase(); // Unreachable
})();
Actual behavior:
The code after the never-returning promise is marked as reachable.
Related Question on StackOverflow: Has more code: https://stackoverflow.com/questions/58732814
Related Issue: https://github.com/microsoft/TypeScript/issues/10973 (although marked as "Working as intended", it was changed later. 3.7.2 behaves like the issue opener expected).
If this is not a bug, what is the background for this behavior?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先复现所提供的 async 示例,并将其可达性与直接的 returnNever() 示例进行比较。阅读 compiler 中围绕 await 和 Promise 的 control-flow、reachability 和 definite-assignment 分析;完成标准是确定该行为是否有意为之,或为预期结果添加一个针对性的回归测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100