[英]Materia-ui and typescript No overload matches this call
I'm converting a js component that uses Material-ui to typescript and I ran into a problem.我正在将使用 Material-ui 的 js 组件转换为 typescript 并且遇到了问题。 This part was rendering a tile-like image in which the component prop was overridden plus additional to prop to make a proper clickable link.这部分正在渲染一个类似平铺的图像,其中组件道具被覆盖,另外还有道具以制作正确的可点击链接。
The error I get is: TS2769: No overload matches this call.我得到的错误是: TS2769:没有重载匹配这个调用。
Here is the code I'm using:这是我正在使用的代码:
Importing statement:进口声明:
import GridListTile from '@material-ui/core/GridListTile';
import { Link } from 'react-router-dom';
And in render function I have:在渲染 function 我有:
<GridListTile
component={Link} <<-- here I get the error
to={'/some-address'}
>
// other components
</GridListTile>
I can silence the error by passing as any
, but then it complains about to prop!我可以通过传递as any
来消除错误,但随后它抱怨支持!
<GridListTile
component={Link as any} <<-- won't complain
to={'/some-address'} <<-- but now here I get the error
>
// other components
</GridListTile>
I want to be able to use Material-ui components and be able to pass another component and the props I want.我希望能够使用 Material-ui 组件并能够传递另一个组件和我想要的道具。 I came across some solutions which were hacks, what is the correct way to handle this situation?我遇到了一些黑客解决方案,处理这种情况的正确方法是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.