Answer the question
In order to leave comments, you need to log in
How to replace/add an array element correctly?
There are some items
and their type@observable items: Array<TCardItem> = [];
export type TCardItem = {
id: string;
photoUrl: string;
name: string;
lastname: string;
phoneValues: Array<number | string>;
address: string;
};
deleteItem = (id: string) => {
this.items = this.items.filter(item => item.id !== id);
};
saveItem = (id: string, modifiedItem: object) => {
this.items = this.items.map(item =>
item.id === id ? modifiedItem : item
);
};
addItem = (idItem: object) => {
this.items = [...this.items, idItem];
};
Type "object[]" cannot be assigned to type "TCardItem[]".
Type '{}' is missing the following properties from type 'TCardItem': id, photoUrl, name, lastname, and 2 more.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question