This typescript function shoud be applicable to two different types of arrays (i.e. arrays with different interfaces) which both have two properties (id and count) in common. The function updates the count property of an item OR task with a given id. But I get a typescript error at the "find" command: "The expression is not callable." If I remove one of the Interfaces, i.e. if I only define the input parameter "items" as a Item-array (Item[]) OR an Task-array (Task[]) it works. But I want to apply the function to both types of arrays.
//interface definitions
export interface Item {
id: number,
count: number,
other: number
}
export interface Task {
id: number,
count: number,
more: string
}
//function
function UpdateCount(items: Item[] | Task[], id: number, count: number) {
let item = items.find(obj => obj.id === id);
if (item !== undefined) {
item.count = count;
}
}