Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this trigger an Identifier Expected error in Typescript?

Tags:

typescript

The second line in this statement causes an error. I understand if I wrap the lambda in parentheses it solves the problem as in the first line. I'm just curious why it is an error, as in JavaScript a lambda there would work fine.

var okay = true && (() => {});
var fails = true && () => {};
like image 661
Breck Avatar asked Jul 18 '14 17:07

Breck


1 Answers

It is a precedence issue:

var fails = true && () => {};
                  // <-- Error: Expression expected

... is equivalent to:

var fails = (true && ()) => {};
like image 188
Paleo Avatar answered Nov 10 '22 00:11

Paleo