javascript-TypeScript:SyntaxError:控制台中出现“意外令牌”消息
作者:互联网
为什么此代码不起作用?
我有以下app.ts
var a = 1;
var b = 3;
console.log(`Before a = ${a}, b = ${b}`);
[a, b] = [b, a];
console.log(`After a = ${a}, b = ${b}`);
当我尝试使用
node app.ts
我有下一个:
[a, b] = [b, a];
^
ReferenceError: Invalid left-hand side in assignment
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3
但我期望:
Before a = 1, b = 2
After a = 2, b = 1
TypeScript版本1.8.10
解决方法:
您需要先编译代码.
tsc app.ts
然后用
node app.js
标签:destructuring,javascript,typescript 来源: https://codeday.me/bug/20191012/1898403.html