Skip to content

Why doesn't awaiting a Promise<never> change reachability? #34955

Description

TypeScript Version: 3.7.2

Search Terms:

  • "Promise"
  • await
  • reachability analysis
  • control flow analysis
  • definite assignment analysis

Code

(async()=>{letb: string;leta1=awaitPromise.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:

functionreturnNever(): never{thrownewError();}(async()=>{letb: string;leta0=returnNever();// a0 is neverb="";// Unreachableb.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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: check: Control FlowThe issue relates to control flow analysis

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions