我有这个虚拟数据,我想输入:
export default interface Report {
id: number;
name: string;
lastName: string;
}
export const dummyReports: Report[] = [
{ id: 23, name: 'Carlo', lastName: 'Magno' },
{ id: 11, name: 'Albert', lastName: 'Camus' },
{ id: 51, name: 'Oliver', lastName: 'Khan' }
];
export const dummyReportsArr: Report[] = [
dummyReports, // THIS IS THE LINE THROWING THE ERROR
{ ...dummyReports, id: 9000 }
];
Type 'Report[]' is missing the following properties from type 'Report': id, name, lastName ts(2739)
我想念什么?
答案 0 :(得分:0)
您已将dummyReportsArr
设置为Report[]
类型。但是,您要为其分配2D数组
dummyReportsArr = [
[ {}, {}, {} ], // dummyReports
{ 0: {}, 1: {}, 2: {}, id: 9000 } // an object with numeric indices
]
数组中的第一项是dummyReports
数组。第二个是对象。在{}
内扩展数组会创建一个对象,该对象的数组索引为对象的键。这些都不是Report