I am using Typescript 1.7 and React 0.14 with the new ES6 systax and I'm having the following destructuring assignment, as explained here as well.
let x0, x1, y0, y1;
if(this.props.viewport) {
{x0, x1, y0, y1} = this.props.viewport;
}
However, I'm getting the Declaration or statement expected
error. What am I doing wrong?
Thanks
If you use IntelliJ as your IDE and are getting the "Declaration or statement expected" error, try closing and re-opening the file or restarting your IDE as it sometimes glitches. Make sure you aren't using any reserved words when declaring variables.
The "Expression expected" TypeScript error occurs when we have a syntax error in our code or our code editor is using an older version of TypeScript. To solve the error, make sure to correct and syntax errors and use a recent version of the TypeScript compiler.
So, I found the problem. Had to wrap the whole line in parenthesis. So the following is correct.
let x0, x1, y0, y1; if(this.props.viewport) { ({x0, x1, y0, y1} = this.props.viewport); }
I had this problem because I was trying to use case
as a variable name e.g. var case = ...
. Now I know this error was because case
is already used by JavaScript's Switch Statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With