为什么这会在 Typescript 中触发 Identifier Expected 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24830687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:55:24  来源:igfitidea点击:

Why does this trigger an Identifier Expected error in Typescript?

typescript

提问by Breck

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.

此语句中的第二行导致错误。我知道如果我将 lambda 括在括号中,它可以解决第一行中的问题。我只是好奇为什么它是一个错误,因为在 JavaScript 中,一个 lambda 可以正常工作。

var okay = true && (() => {});
var fails = true && () => {};

回答by Paleo

It is a precedence issue:

这是一个优先级问题:

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

... is equivalent to:

...相当于:

var fails = (true && ()) => {};