Open
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?