Answer the question
In order to leave comments, you need to log in
How to iterate an object that inherits from an interface?
I have a tasks object that inherits from the ITaskListState interface. I need to go through all the fields of an object and filter them by condition.
tasks:
tasks: ITaskListState = {
tasksToDo: new Array<ITaskItem>(),
tasksInProgress: new Array<ITaskItem>(),
finishedTasks: new Array<ITaskItem>(),
}
export interface ITaskListState
{
tasksToDo: Array<ITaskItem>,
tasksInProgress: Array<ITaskItem>,
finishedTasks: Array<ITaskItem>,
}
filterTasks(filteredTask: ITaskItem)
{
for (let key in this.tasks)
{
this.tasks[key] = this.tasks[key].filter((task: ITaskItem) => task !== filteredTask);
console.log(key);
}
}
Answer the question
In order to leave comments, you need to log in
filterTasks(filteredTask: ITaskItem) {
const keys = Object.keys(this.tasks) as Array<keyof ITaskListState>;
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
this.tasks[key] = this.tasks[key].filter((task: ITaskItem) => task !== filteredTask);
console.log(key);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question