【发布时间】:2016-04-18 13:10:47
【问题描述】:
我有以下 TypeScript
var foo = (...myParams) => {
for (var i = 0; i < myParams.length; i++){
console.log(myParams[i] + " ");
}
};
foo('a', 'b', 'c');
但是,当它被 WebStorm 编译时发现编译后的代码有错误:
当它被Node rune时,Node无法识别rest表达式。
C:\PluralSight\TypeScript>node rest-parameter.js
C:\PluralSight\TypeScript\rest-parameter.js:5
var foo = (...myParams) => {
^^^
SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
【问题讨论】:
-
@squint 酷链接。 Node 只是不支持它们。 C'est la vive。
-
@BanksySan 如果您将 typescript 更改为 target ES5 它将起作用
-
干杯 @DavidSherret,我可以在 WebStorm 中做到这一点吗?不必在命令行中使用 tsc 就不会那么麻烦了。
-
@BanksySan 您应该考虑使用tsconfig.json 文件——在
"compilerOptions"下指定"target": "ES5"。 WebStorm 应该支持这一点。
标签: javascript node.js typescript