我正在尝试创建一个模拟应用程序,将一些数据显示为按钮列表。我实施了一切,但现在我正面临着这个问题。我初始化了一个数组和另一个类的数据。数组中的泛型?
-items.ts
export class ItemPage {
items: Item[] = [];
constructor() {
this.items.push(
new Item(1, 'Apple', 'Green', 6, true));
this.items.push(
new Item(2, 'Banana', 'Yellow', 15, false));
}
和数据类看起来像这样
-item.ts
export class Item {
constructor(
id: number,
fruit: string,
color: string,
quantity: number,
onStock: boolean,
) { }
}
我现在面临一个问题,items: Item[] = [];
当我运行ionic serve
。它说Generic type 'Item' requires 2 type argument(s)
和type Item<K extends string, T> = { [P in K]: T; } Construct a type with a set of properties K of type T
。
我试图解决它,但它没有帮助,有没有人有任何想法如何解决这个问题?
谢谢
看起来'Item'是Ionic中的保留字/类。尝试将您的“Item”更改为不同的名称。 –
我试过你的建议,但我仍然有同样的问题 – Maged
项目 []也许? –