-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysis
Milestone
Description
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: #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?
HaimWix, ExE-Boss, k-yle, kiraind, felix-gohla and 27 morek-yle and sempasha
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Control FlowThe issue relates to control flow analysisThe issue relates to control flow analysis