Closed
Description
TypeScript Version: 1.8.10
NodeJS LTS Version: 4.4.7
I have a project, which I write for NodeJS. I use async/await
so there is need to set tartget: es6. But when I wrote function(or lamba) with default parameter value, compiler work well, but NodeJS gave me an error.
TSConfig
{
"compilerOptions": {
"target": "es6",
"module": "commonjs"
}
}
Code
function foo(bar = 1) {
console.log(bar);
}
foo();
Expected behavior:
Output JS:
function foo(bar) {
if (bar === void 0) { bar = 1; }
console.log(bar);
}
foo();
Display 1 as output.
Actual behavior:
Output JS:
function foo(bar = 1) {
console.log(bar);
}
foo();
Run this code with NodeJS (v5.7.0) and get the error:
function foo(bar = 1) {
^
SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:141:18)
at node.js:933:3
Assumption:
It would be great to set default parameters values via if
for NodeJS, in case that problem occurs on NodeJS LTS.