我刚开始使用 TypeScript 和 Angular 2。我正在使用 Angular 2-cli 的版本1。编译时,我得到了一个错误提示,说 "is not assignable to type Assignment[]"。我查看了数据类型,一切看起来都还好,但我不确定错误具体是什么。感谢你的帮助。
以下是控制台中错误的图片。
这是 data.ts 文件 - 这是数组中出现的两个条目之一。
以下是控制台中错误的图片。
![enter image description here](https://istack.dev59.com/O37l4.webp)
export const Assignments: Assignment[] = [
{
"a_type": "one",
"a_title": "Assignment 1",
"symbol": 1,
"show": false,
"tooltip": {
"left": 82
},
"buttonPos":{
"left": 130
},
"printTop": 0,
"instructions": "Instructions here",
"due_date": "sept-15.png",
"percentage": "10.png",
"taskA": {
"name": "Option A",
"a_title": "Task A",
"information": "Instructions for task A",
"selectA": true
}
}, {
"a_type": "two",
"a_title": "Assignment 2",
"symbol": 2,
"show": false,
"sub_a_title": "Assignment Information",
"tooltip": {
"left": 200
},
"buttonPos":{
"left": 250
},
"printTop": 250,
"instructions": "Instructions here",
"due_date": "29.png",
"percentage": "10.png",
"taskA": {
"a_title": "Assignment 2 info",
"name": "Option A",
"information": "Instructions for task A",
"selectA": false
},
"taskB": {
"a_title": "Assignment 2 info",
"name": "Option B",
"information": "Instructions for task B",
"selectB": false
}
}
]
assignment.ts - 这里是数据类型
export class Assignment {
a_type: string;
a_title: string;
symbol: any;
show: boolean;
tooltip: any;
left: number;
buttonPos:any;
printTop: number;
instructions: string;
due_date: string;
percentage: string;
taskA: any;
name: string;
information: string;
selectA: boolean;
taskB: any;
selectB: boolean;
}