我有这样的数据示例,我收到了:
{
Europe: {
WestEurope: {
Belgium: [French, English, Dutch]
}
}
}
不确定如何为这种动态结构创建接口(interface),我有一棵树:
Object->Object(of Regions)->Object(of SubRegions)->Object(of Countries)->ArrayOfStrings(of languages)
我试过了:
export interface Localisation {
[key: string]: Localisation;
}
export interface Region {
[key: string]: Region;
}
export interface SubRegion {
[key: string]: SubRegion;
}
export interface Country {
[key: string]: Country;
}
export interface Language {
[index: number]: Array<string>;
}
但它们不是“链接”的 -> 所以“本地化”不知道它包含“区域”等。我想以某种方式连接它们。可能吗?
最佳答案
这个怎么样?
interface Country {
[proporty: string]: string[];
}
interface SubRegion {
[property: string]: Country;
}
interface Region {
[property: string]: SubRegion;
}
interface Localisation {
[property: string]: Region;
}
关于javascript - typescript :定义没有特定键和链对象的接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56631046/