typescript - 将主题应用于材质 UI 菜单组件
问题描述
我有下一个代码,用于应用自定义主题:
import Menu from '@material-ui/core/Menu';
import { createStyles, withStyles, Theme } from '@material-ui/core/styles';
const myMenu = withStyles( ( theme: Theme ) =>
createStyles( {
root: {
backgroundColor: theme.palette.primary.main,
},
} ),
)( Menu );
但我收到下一个错误:
Argument of type 'ComponentType<MenuProps>' is not assignable to parameter of type 'ComponentType<ConsistentWith<MenuProps, { classes: Record<"root", string>; }> | ConsistentWith<PropsWithChildren<MenuProps>, { ...; }>>'.
Type 'ComponentClass<MenuProps, any>' is not assignable to type 'ComponentType<ConsistentWith<MenuProps, { classes: Record<"root", string>; }> | ConsistentWith<PropsWithChildren<MenuProps>, { ...; }>>'.
Type 'ComponentClass<MenuProps, any>' is not assignable to type 'ComponentClass<ConsistentWith<MenuProps, { classes: Record<"root", string>; }> | ConsistentWith<PropsWithChildren<MenuProps>, { ...; }>, any>'.
Types of property 'propTypes' are incompatible.
Type 'WeakValidationMap<MenuProps> | undefined' is not assignable to type
解决方案
你必须在函数(theme: Theme) =>
内部移动。createStyles
像这样:
import Menu from '@material-ui/core/Menu';
import { createStyles, withStyles, Theme } from '@material-ui/core/styles';
const myMenu = withStyles(createStyles((theme: Theme) => {
root: {
backgroundColor: theme.palette.primary.main,
},
}),
)( Menu );
推荐阅读
- python - 从 3D numpy 数组中选择 N 个随机行
- sql - Postgresql 子查询包含错误
- node.js - /api上暴露的mongoDB数据库,我该如何隐藏它?
- python - 无法打开登录请求的数据库“\'name\': \'master\'”。登录失败
- amazon-web-services - Elastic Beanstalk 环境上的包 Persitence
- c - 同时拥有名称和指向结构的指针是否有意义?
- r - 使用 shinyjqui 绘制 imageOutput() 的纵横比出错
- python - Django 1.4: Tests are very slow
- node.js - 如何使用 npm V6 优雅地安装 peerDepencies?
- r - 在 R 中,是否可以对矩阵行和列索引使用动态公式?