reactjs - Material-ui 的 CardActionArea 组件属性的打字稿错误
问题描述
Material-ui按钮 | 第三方路由库文档指出,我们需要让适配器将react-router-dom/Link
组件封装到 Button 中。但是对 a CardActionArea
(根据文档,这是一个 BaseButton)执行相同操作会产生以下 Typescript 错误:
main.tsx:24:10 - error TS2322: Type '{ children: Element; component: ForwardRefExoticComponent<LinkProps & RefAttributes<HTMLAnchorElement>>; to: string; }' is not assignable to type 'IntrinsicAttributes & CardActionAreaProps & { children?: ReactNode; }'.
Property 'component' does not exist on type 'IntrinsicAttributes & CardActionAreaProps & { children?: ReactNode; }'.
14 <CardActionArea component={AdapterLink} to="/foo">
~~~~~~~~~~~~~~
该代码仍然有效。这是一个显示第 14 行错误消息的最小示例:
注意:第 6 行有一个错误,因为 Codesandbox 在 TypeScript 文件中运行 eslint,所以忽略它。
解决方案
这对我有用,我在 TypeScript 中没有错误:
<CardActionArea {...{ component: Link, to }}>
推荐阅读
- oracle - 在 Oracle Linux 7.4 上安装 Golden Gate,Oracle 版本为 12.2.0.1
- angular - 合并一个 Observable 和 Promise 到一个对象
- javascript - 如何在 React 中的滚动事件上获得更好的性能
- forms - 如何通过另一个选择在输入填充中获取值
- python - 为 python2 和 python3 安装 py2deb
- javascript - 如何在脚本中访问数组中的项目?
- java - 在设置中启用 NotificationListenerService 不显示应用程序 - Android Studio - Java
- javascript - Pug/jade 没有在 Express js 应用程序中获取变量
- java - PostKey 给出 NulllPointerException。不在数据库中的某个帖子节点下创建评论
- sql - Oracle 查询组合 2 个选择