0

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 ?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

oh, ok, I thought they were included in es6. That does answer the question though, so thanks !
If it answers the question, can you mark it as answer? ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.