我的界面中定義了一組如下所示的對象:myArray: [{ id: number; item: string; checked: boolean;}]我正在嘗試使用以下語句克隆數組:let newArray = myArray.map(x => Object.assign({},x));當我嘗試將新數組分配給我的原始數組時,出現以下錯誤: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看起來對象數組正在轉換為數組對象。
在 TypeScript 中克隆對象數組
滄海一幻覺
2023-03-18 16:14:05