interface item {
first: string;
last: string;
}
const itemList = Item[];
updateAttribute = (index, attributeToUpdate) => {
itemList[index].attributeToUpdate = "New first/last"
}
The snippet above showcases an interface named item
with properties first
and last
. There is also an array called itemList
, specifically containing objects of type item
.
An attempt was made to create a function that takes an index from the array and a string
called attributeToUpdate
, which could be either first
or last
.
However, this implementation led to a TypeScript error stating 'Property 'attributeToUpdate' does not exist on type 'item'.' What would be the best approach to tackle this issue?