Announcing TypeScript 2.1
Підписуйтеся на Telegram-канал «DOU #tech», щоб не пропустити нові технічні статті
Object Rest & Spread
We’ve been excited to deliver object rest & spread since its original proposal, and today it’s here in TypeScript 2.1. Object rest & spread is a new proposal for ES2017 that makes it much easier to partially copy, merge, and pick apart objects. The feature is already used quite a bit when using libraries like Redux.With object spreads, making a shallow copy of an object has never been easier:
let copy = { ...original };
Similarly, we can merge several different objects so that in the following example, merged will have properties from foo, bar, and baz.
let merged = { ...foo, ...bar, ...baz };
We can even add new properties in the process:
let nowYoureHavingTooMuchFun = { hello: 100, ...foo, world: 200, ...bar, }
...
59 коментарів
Додати коментар Підписатись на коментаріВідписатись від коментарів