Monday, April 23, 2018

What happens when you forget the spread operator in TypeScript?

This...

let yin = {
   foo: 13,
   bar: 42,
   baz: 69,
   qux: 86
}
let yang = {
   yin
}
console.log(yang);

 
 

...gives us this:

{
   yin: {
      foo: 13,
      bar: 42,
      baz: 69,
      qux: 86
   }
}

 
 

While this...

let yin = {
   foo: 13,
   bar: 42,
   baz: 69,
   qux: 86
}
let yang = {
   ...yin
}
console.log(yang);

 
 

...gives us this instead:

{
   foo: 13,
   bar: 42,
   baz: 69,
   qux: 86
}

No comments:

Post a Comment