I have an array of objects like below defined in my interface:
myArray: [{
id: number;
item: string;
checked: boolean;
}]
I am trying to clone the array using the below statement:
let newArray = myArray.map(x => Object.assign({},x));
When I am trying to assign a new array to my original array, I am getting the below error:
Type '{ id: number; item: string; checked: boolean; }[]' is not assignable to type
'[{ id: number; item: string; checked: boolean; }]'.
Target requires 1 element(s) but source may have fewer
It looks like the array of objects is being transformed to an object of array.
myArrayis defined as a tuple, not an array, type. You've said it should have exactly one entry..mapmakes no such guarantee. Your initial type is probably wrong, or if you do only have one entry you don't need to.map.myArray: [{ id: number; item: string; checked: boolean; }]tomyArray: { id: number; item: string; checked: boolean; }[]