Thursday, June 21, 2018

Did you know that if you create a trailing variable led by the spread operator in TypeScript object destructuring that everything you didn't pull out in the other variables ends up in the new, watered-down variable?

Consider:

var hogwash = {
   foo: 13,
   bar: 42,
   baz: 69,
   qux: 86
};
const { bar, baz, ...malarkey } = hogwash;
console.log(bar);
console.log(baz);
console.log(malarkey);

 
 

The following will be logged:

  • 42
  • 69
  • {
       foo: 13,
       qux: 86
    }

No comments:

Post a Comment