-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Description
🔎 Search Terms
finally, unreachable, condition, never
🕗 Version & Regression Information
- This builds fine in 3.2,
- produces a type error regarding the return type in 3.3 through 3.6,
- and starting 3.7, including the latest native preview, it produces the unreachable code error
⏯ Playground Link
💻 Code
function report(e): never {
throw e;
};
const foo = async (): Promise<number> => {
try {
return 3;
} catch (e) {
report(e);
} finally {
if (true) {
console.log("heh");
}
}
};🙁 Actual behavior
test.ts:11:5 - error TS7027: Unreachable code detected.
11 if (true) {
~~~~~~~~~~~
12 console.log("heh");
~~~~~~~~~~~~~~~~~~~~~~~~~
13 }
~~~~~
test.ts:12:7 - error TS7027: Unreachable code detected.
12 console.log("heh");
~~~~~~~~~~~~~~~~~~~
🙂 Expected behavior
Builds fine.
Additional information about the issue
This error vanishes if I do any of the following:
- Remove the explicit
neverreturn type ofreportError(although that resurfaces the return type error) - Remove the call to
reportErrorentirely, or the wholecatchblock - Remove the
ifcondition from thefinallyblock, but leave in theconsole.logcall
I found a similar issue #61259, but it does not include a catch block, which is integral to the issue here - although the issues might still be related. Similarly to that issue, the finally block also becomes reachable when adding another return to the catch block, but it is itself unreachable.
jcalz
Metadata
Metadata
Assignees
Labels
No labels