在接口属性中声明两种类型

时间:2021-03-09 14:58:11

标签: reactjs typescript next.js typescript-typings theme-ui

我需要声明两个语句:

declare module "react" {
  interface Attributes {
    sx?: ThemeUIStyleObject;
  }
}

declare module "react" {
  interface Attributes {
    sx?: SxStyleProp;
  }
}

因为如果没有,主题 ui 错误会出现在 sx 道具中。

我已经试过了:

declare module "react" {
  interface Attributes {
    sx?: ThemeUIStyleObject | SxStyleProp;
  }
}

但仅适用于第一个对象 (ThemeUIStyleObject)

1 个答案:

答案 0 :(得分:0)

尝试&加入这两种类型。

sx?: ThemeUIStyleObject & SxStyleProp;