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

前端 未结 3 1763
鱼传尺愫
鱼传尺愫 2020-12-11 01:37

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 th

相关标签:
3条回答
  • 2020-12-11 02:20

    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.

    0 讨论(0)
  • 2020-12-11 02:31

    I was making following mistake

    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
    
    0 讨论(0)
  • 2020-12-11 02:34

    TypeScript 2.1 does support this feature.

    Here

    0 讨论(0)
提交回复
热议问题