我正在使用TypeScript1.7和React 0.14和新的ES6 systax,并且我有以下解构任务,正如here所解释的那样。
let x0, x1, y0, y1;
if(this.props.viewport) {
{x0, x1, y0, y1} = this.props.viewport;
}但是,我得到了Declaration or statement expected错误。我做错了什么?
谢谢
发布于 2016-02-23 19:32:08
所以,我找到了问题所在。我不得不把整行都括在括号里。因此,以下内容是正确的。
let x0, x1, y0, y1;
if(this.props.viewport) {
({x0, x1, y0, y1} = this.props.viewport);
}发布于 2018-07-27 04:34:48
我遇到这个问题是因为我试图使用case作为变量名,例如var case = ...。现在我知道这个错误是因为JavaScript的Switch Statement已经使用了case。
https://stackoverflow.com/questions/35576307
复制相似问题