【发布时间】:2021-08-10 20:43:49
【问题描述】:
晚上好,
只是一个快速的,我在打字稿方面不是那么好,但我仍然在寻找解决泛型的方法。 当然有一种更简洁或更简洁的方法来执行以下操作,在这种情况下最佳做法是什么?
export interface Fruit {
colour: string;
age: number;
edible: boolean;
}
export interface A {
Apple: Fruit[];
Banana: Fruit[];
Peach: Fruit[];
Plum: Fruit[];
Melon: Fruit[];
}
export interface B {
diffApple: Fruit[];
diffBanana: Fruit[];
diffPeach: Fruit[];
diffPlum: Fruit[];
diffMelon: Fruit[];
}
export interface FruitIndex
extends A, B, (etc)
我有这种情况,但是对于多个接口,它看起来真的很不整洁。 TIA
【问题讨论】:
-
这个问题不涉及泛型。另外,我不确定你认为什么是“整洁”和“不整洁”,我也不确定你想以“更干净”或“更整洁”的方式做这部分。就像,你可以用this 声明
A和B没有那么多冗余,但也许这不是你想要做的? -
是的,没有泛型,但我想也许会有一种更简洁的方式来使用泛型。但是,您所链接的正是我正在寻找的。谢谢!更整洁。
-
好吧,有机会我可以写下来作为答案。
标签: typescript types interface