如何在打字稿中组合多个接口?

时间:2019-07-17 11:05:42

标签: typescript

我有几个接口:

interface TabViewData {
    constTypeList: Object,
    materialList: Object,
    ownerList: Object | null,
    creativeList: Object | null,
    dataList: {}[]
}

export interface CitiesTabViewData extends TabViewData {
    cityList: : Object,
    dataByCity: Object
}

export interface MacroRegionsTabViewData extends TabViewData {
    macroRegionList:: Object
    dataByMacroRegion: Object,
}

export interface TotalTabViewData extends TabViewData {
    dataTotal: Object,
}

如何创建一个将它们全部组合在一起的界面(假设它们可能具有相同的属性)?我尝试过:

interface State extends Partial<CitiesTabViewData, MacroRegionsTabViewData> 
{
showModal: boolean
}

但Partial仅接受一个参数((((

1 个答案:

答案 0 :(得分:1)

尝试

interface State extends Partial<CitiesTabViewData>, Partial<MacroRegionsTabViewData> 
{
    showModal: boolean
}