【问题标题】:Extend interface from another - MUI从另一个扩展接口 - MUI
【发布时间】:2020-05-21 22:18:52
【问题描述】:

我有一个界面

interface ThemeBase {
  colors: {
    [key: string]: Color;
  };
  borderRadius: {
    base: string;
    mobile: string;
  };
  navbar: {
    'z-index': number;
  };
  typography: {
    rootBase: string;
    fontBase: string;
  };
}

我想用这个界面扩展 MUI 主题。 这个解决方案对我有用:

declare module '@material-ui/core/styles/createMuiTheme' {
  interface Theme extends ThemeBase {}
  // allow configuration using `createMuiTheme`
  interface ThemeOptions extends ThemeBase {}
}

但是我有一个来自 eslint 的错误

error 一个声明没有成员的接口等价于它的 超类型@typescript-eslint/no-empty-interface

如何在没有 Theme 和 ThemeOptions 代码重复的情况下解决此问题

【问题讨论】:

  • type Theme = ThemeBase 也许?
  • 不,这在常见情况下有效,但不适用于 Material UI (
  • 你真的试过了吗?根据应该工作的规范(没有可用的游乐场)
  • 是的,我现在正在尝试创建一个游乐场

标签: javascript reactjs typescript material-ui eslint


【解决方案1】:

这是 IMO 完全可以将/* eslint-ignore @typescript-eslint/no-empty-interface */ 放在第一行的少数示例之一。虽然我不会在常规代码中这样做,但模块扩充有点不同,在这里尝试找到解决方法是没有意义的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 2018-07-16
    • 2016-04-28
    • 1970-01-01
    • 2019-04-06
    相关资源
    最近更新 更多