reactjs - 如何从“material-ui”导入类型?
问题描述
我正在开发一个react
带有material-ui
in的应用程序typescript
。我想知道在哪里可以找到material
组件的所有类型定义。我已尝试安装@types/material-ui
,但效果不佳。请参见下面的示例:
import * as React from 'react';
import SvgIcon from '@material-ui/core/SvgIcon';
import { SvgIconProps } from "material-ui";
export const Logo = (props: SvgIconProps) => (
<SvgIcon {...props}>
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z" />
</SvgIcon>
);
我在编译时遇到以下错误:
Type '{ children: Element; color?: string | undefined; hoverColor?: string | undefined; onMouseEnter?: ((event: MouseEvent<{}, MouseEvent>) => void) | undefined; onMouseLeave?: ((event: MouseEvent<{}, MouseEvent>) => void) | undefined; ... 413 more ...; ref?: string | ... 3 more ... | undefined; }' is not assignable to type 'SvgIconProps'.
Types of property 'color' are incompatible.
Type 'string | undefined' is not assignable to type '"inherit" | "default" | "disabled" | "error" | "primary" | "secondary" | "action" | undefined'.
Type 'string' is not assignable to type '"inherit" | "default" | "disabled" | "error" | "primary" | "secondary" | "action" | undefined'.
解决方案
具体道具可以导入材质UI本身。
对于SvgIcon
问题中的组件,可以使用以下命令导入Prop Typing :
import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
推荐阅读
- python-3.x - 查找不允许我将字符串转换为浮点数的数据
- visual-studio-code - 始终在当前选项卡中从资源管理器打开文件
- machine-learning - 多类分类问题的精确与召回
- ruby-on-rails - Amazon Comprehend Medical 返回过滤值
- api - Varnish 不缓存简单的 GET 请求到后端
- c# - 在 C# 中序列化这些值以在 C++ 中作为已知结构正确读取时遇到问题
- javascript - 在javascript中的多模块上定义相同的变量名有什么问题吗
- apache-kafka - 卡夫卡推拉窗
- gcc - 搜索最近的 GCC GIMPLE 语法
- c# - 将 excel 文件保存在用户的下载文件夹中会产生错误(.NET Core Razor 页面)