打字稿嵌套对象,因此属性不会重复

时间:2017-09-16 22:16:18

标签: typescript

我的界面目前看起来像这样。是否有可能重构它,以便在两者中不再重复属性。

export interface Navigation {
    name: string;
    roles: Array<number>;
    sublinks: NavigationItem[];
}

export interface NavigationItem  {
    name: string;
    roles: Array<number>;
    url: string;
}

1 个答案:

答案 0 :(得分:2)

export interface NavigationBase {
    name: string;
    roles: number[];
}

export interface Navigation extends NavigationBase {
    sublinks: NavigationItem[];
}

export interface NavigationItem extends NavigationBase {
    url: string;
}