ECMAScript 6 在对象解构中扩展了语法。支持 TypeScript 和 Babel

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

以下是有效的 ECMAScript 6 吗? 最新版本的 Babel 似乎支持它,但 TypeScript 不支持它。 我找不到任何处理这种情况的 ES6 参考资料。

var a = { foo : 'foo' };
var b = { ...a };

不,这不是有效的 ECMAScript 6。ES6 仅支持函数参数和数组解构中的剩余语法,以及函数调用和数组构造中的传播语法。

It seems to be supported by the latest version of Babel

Babel 确实实现了 objectRestSpread ES7 proposal as a experimental plugin。您不应该使用此功能,它可能随时中断。

TypeScript 2.1 支持此功能。

Here

我犯了以下错误

const o = { p : { q:1, r:2 } };
const {{q,r}} = o;

later realized that it is important for me to direct q and r from p, so it was basically a syntax error in my case, so corrected code with following syntax.

const {p:{q,r,s=9}} = o;
console.log(q,r,s); // 1,2,9