TypeScript Version:
master (a535460), built from source. Also occurs on current Playground.
Code
switch (1) {
case (a): {
if (c) {}
}
}
Expected behavior:
Error about the unknown names a and c. Compiles to exactly the same JS, since the code is already plain JavaScript.
Actual behavior:
Syntax errors.
tmp.ts(3,12): error TS1005: ';' expected.
tmp.ts(4,1): error TS1005: ':' expected.
tmp.ts(5,1): error TS1128: Declaration or statement expected.
On Playground, you get some more errors (looks like CLI aborts at the syntax errors while Playground continues with type checking).
Type '(a: any) => { if(c: any): any; }' is not assignable to type 'number'.
A function whose declared type is neither 'void' nor 'any' must return a value.
Also, a is documented as “parameter”. So apparently the parser thinks this is a function expression, not a case clause and following block.
This is fairly fragile. Many changes to the code will result in the error vanishing, including:
- Changing
a to 1
- Changing
c to 1
- Removing the parentheses around
a
- Adding an extra pair of parentheses around
a
- Removing the curly braces of the
case block
- Replacing the empty
if block with the empty statement ;
- Replacing the empty
if block with the nonempty statement console.log("foo");
- Completely removing the
if statement
TypeScript Version:
master (a535460), built from source. Also occurs on current Playground.
Code
Expected behavior:
Error about the unknown names
aandc. Compiles to exactly the same JS, since the code is already plain JavaScript.Actual behavior:
Syntax errors.
On Playground, you get some more errors (looks like CLI aborts at the syntax errors while Playground continues with type checking).
Also,
ais documented as “parameter”. So apparently the parser thinks this is a function expression, not a case clause and following block.This is fairly fragile. Many changes to the code will result in the error vanishing, including:
ato1cto1aacaseblockifblock with the empty statement;ifblock with the nonempty statementconsole.log("foo");ifstatement