我正在尝试创建一个界面
export interface MenuItem { title: string; component?: any; click?: any; icon: string; }
component
click
不是使用单个接口,因为类型没有条件逻辑并且不能相互依赖,但是您可以通过拆分接口:
export interface BaseMenuItem { title: string; icon: string; } export interface ComponentMenuItem extends BaseMenuItem { component: any; } export interface ClickMenuItem extends BaseMenuItem { click: any; } export type MenuItem = ComponentMenuItem | ClickMenuItem;