[英]Extend interface from another - MUI
I have an interface我有一个界面
interface ThemeBase {
colors: {
[key: string]: Color;
};
borderRadius: {
base: string;
mobile: string;
};
navbar: {
'z-index': number;
};
typography: {
rootBase: string;
fontBase: string;
};
}
And I want to extend MUI theme with this interface.我想用这个界面扩展 MUI 主题。 This solution work for me:
这个解决方案对我有用:
declare module '@material-ui/core/styles/createMuiTheme' {
interface Theme extends ThemeBase {}
// allow configuration using `createMuiTheme`
interface ThemeOptions extends ThemeBase {}
}
But I have an error from eslint但是我有一个来自 eslint 的错误
error An interface declaring no members is equivalent to its supertype @typescript-eslint/no-empty-interface
错误声明没有成员的接口等效于其超类型@typescript-eslint/no-empty-interface
How to fix this without code duplication for Theme and ThemeOptions如何在没有主题和主题选项的代码重复的情况下解决此问题
This is one of those few examples where it's completely fine IMO to just put /* eslint-ignore @typescript-eslint/no-empty-interface */
in the first line.这是 IMO 完全可以将
/* eslint-ignore @typescript-eslint/no-empty-interface */
放在第一行的少数几个例子之一。 While I wouldn't do it in regular code, module augmentation is a bit of a different beast, there's no point trying to find a workaround here.虽然我不会在常规代码中这样做,但模块扩充有点不同,在这里尝试找到解决方法是没有意义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.