I have an array of typed objects - all objects are of type: TodoModel. When I filter them, to adjust the content on the UI, you have to create a new array and adjust the properties on the item that was changed for the filter to refilter in angular2. When I create the new array and add the changed object, the object is of no type, while the other 2 objects in the array are still of type: TodoModel. I can't figure out how to assign a type to the new object :( Thanks in advance for any help!
Here is the code for the logic & below I have a screen shot of the before and after for the mutated arrays:
case 'TOGGLE_TODO':
const todo: ITodoModel = payload;
const i = state.indexOf(todo);
const status = todo.status == "started" ? "completed" : "started";
const toggledTodo:ITodoModel = Object.assign(<ITodoModel>{}, todo, {status});
state = [
//... = spread operator - bascially loops through the array
...state.slice(0,i), // check items before
toggledTodo, // clicked item
...state.slice(i + 1) // check items after
];
console.log('toggle state');
console.log(state);
return state;
