I was just browsing through some typescript generated code and was somewhat surprised at the code for spread
test.ts
let task = { ...data };
test.js
let task = Object.assign({}, data);
I double-checked the tsconfig.json
file and have under compilerOptions
"target": "es2017",
I thought that the spread operator was valid es6 code
So, changed the target to read
"target": "ESNext",
and my test.js now has
let task = { ...data };
I'm using typescript 2.7.2
So, basically the question boils down to why do I need EsNext instead of es2017 / es6 ?
The Object rest/spread properties are, unlike the Array rest/spread properties, not included in the ES2017 spec. They are however included in the ES2018 spec.