Thursday, February 1, 2018

Use the TypeScript spread operator at an object!

let foo = {
   bar: 13,
   baz: 42
};
let qux = {
   ...foo,
   baz: 69
};

In this code all of the properties in foo are copied to qux and then the baz on qux is reset. The properties are deep copied so resetting the baz on qux does not sabotage the baz on foo.

No comments:

Post a Comment