Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ECMAScript 6 spread syntax in object deconstruction. Support in TypeScript and Babel

Is the following valid ECMAScript 6? It seems to be supported by the latest version of Babel but it isn't by TypeScript. I couldn't find any ES6 references dealing with this case.

var a = { foo : 'foo' };
var b = { ...a };
like image 735
user3084263 Avatar asked Jun 29 '15 12:06

user3084263


People also ask

Can you use the spread operator on objects?

Spread syntax can be used when all elements from an object or array need to be included in a new array or object, or should be applied one-by-one in a function call's arguments list.

Does spread operator work on objects JavaScript?

The spread operator … is useful for working with arrays and objects in JavaScript. It is a convenient feature added in ES6 (ES2015).

What is spread operator in ES6?

The JavaScript spread operator ( ... ) allows us to quickly copy all or part of an existing array or object into another array or object.


1 Answers

No, this is not valid ECMAScript 6. ES6 does only support rest syntax in function parameters and array destructuring, and spread syntax in function calls and array construction.

It seems to be supported by the latest version of Babel

Babel does implement the objectRestSpread ES7 proposal as a experimental plugin. You shouldn't use this feature, it may break at any time.

like image 91
Bergi Avatar answered Sep 20 '22 18:09

Bergi