我正在转换一个使用Material-ui来打字的js组件,但遇到了问题。这部分是渲染一个类似瓦片的图像,其中覆盖了 component 道具以及其他 to 道具,以形成适当的可点击链接。
我得到的错误是: TS2769:没有重载匹配此调用。
这是我正在使用的代码:
进口声明:
import GridListTile from '@material-ui/core/GridListTile';
import { Link } from 'react-router-dom';
在渲染功能中,我有:
<GridListTile
component={Link} <<-- here I get the error
to={'/some-address'}
>
// other components
</GridListTile>
我可以通过传递as any
来使错误保持沉默,但随后它会抱怨 to 道具!
<GridListTile
component={Link as any} <<-- won't complain
to={'/some-address'} <<-- but now here I get the error
>
// other components
</GridListTile>
我希望能够使用Material-ui组件,并能够传递另一个组件和我想要的道具。 我遇到了一些被黑客入侵的解决方案,处理这种情况的正确方法是什么?