Typescript Spread Operator
While working through some introductory tutorials on Angular2 and Typescript a new operator came to my attention which takes the form of an ellipsis and is called the Spread Operator.
ECMAScript 6 was finalized in June 2015 and it introduced the spread operator as a better version of the the existing apply method.
Using the existing Function.prototype.apply you pass two arguments, a this parameter and a single array which is converted into a list of arguments to the function which apply is called on.
In ES6 using the spread operator you can instead prefix the arguments with …
Angular2 and Typescript
When creating an Angular2 application using Typescript the spread operator becomes very useful. When updating an object in for example a todo list array it is recommended to replace the array rather than to update it so any pipes that filter the array contents are informed that the contents have changed. In the toggle function below we can use splice combined with the spread operator to neatly update a todo object within our array of todo objects.