Why am I getting a "Variable foo is declared in case [...] Reference error when accessing" warning?
Minimal example I have is this (it's TypeScript, if it makes a difference):
switch (something) {
case 1:
switch (something_else) {
case "a":
const foo = 123;
const bar = foo * 2;
break;
case "b":
const foo = 456;
const bar = foo * 2;
}
break;
case 2:
const foo = "foo";
break;
}
I get the following warning:

However, I can't see any problem; there is no switch fallthrough, the code is not in a loop, so there is no chance of accidentally using a variable declared in a different switch clause; is this an overzealous static code analyzer, or is the code at fault?
Thanks in advance!
Please sign in to leave a comment.
Please follow https://youtrack.jetbrains.com/issue/WEB-39594 for updates
Wow, thanks for the lighting fast response!