ECMAScript 6 spread syntax in object deconstructio

2020-02-06 05:32发布

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 };

2条回答
闹够了就滚
2楼-- · 2020-02-06 06:06

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.

查看更多
3楼-- · 2020-02-06 06:11

TypeScript 2.1 does support this feature.

Here

查看更多
登录 后发表回答