我正在用React HOC编写组件,但是使用打字稿验证道具时却出现错误。 错误如下
Type'{type:string; imgUrl:任何; vidUrl:任意; }'不可分配 键入“ IntrinsicAttributes&Pick&{ 孩子们?:ReactNode;}'。
我的组件是什么样的(示例):
type Props = {
type: string;
imgUrl: any;
vidUrl: any;
}
const Component = ({type,imgUrl,vidUrl}:Props)=> (
<div>.....
.....
</div>
)
export defualt withTranslation('common')(Component);
答案 0 :(得分:0)
您必须提供正确的组件类型。
import { withTranslation, WithTranslation } from 'react-i18next';
import React from "react";
type Props = {
type: string;
imgUrl: any;
vidUrl: any;
}
const Component: React.FC<Props & WithTranslation> = ({type,imgUrl,vidUrl})=> (
<div>.....
.....
</div>
)
const withTranslationComponent = withTranslation('common')(Component);
export default withTranslationComponent;