我试着到处寻找解决方案,但一切都是徒劳的。我已经尝试更改tsconfig文件选项以及可以在组件本身中完成的所有可能的事情,但我无法弄清楚出了什么问题。我正在使用打字稿2.3。请帮忙。情况就是这样。
export interface AProps{
//some data
};
class A extends React.Component<AProps>{
constructor(props){
super(props);
}
onSubmit(values : any){
}
render(){
}
}
function validate( values :any){
}
function mapDispatchToProps(dispatch :any){
}
const ReduxForm = reduxForm({
validate : validate,
form : 'ABC'
})(
A
)
为了简单起见,我删除了内部内容。在&#34; A&#34;上的reduxForm函数中。我收到了这个错误:
[ts]
Argument of type 'typeof A' is not assignable to parameter of type 'ComponentType<InjectedFormProps<any, {}>>'.
Type 'typeof A' is not assignable to type 'StatelessComponent<InjectedFormProps<any, {}>>'.
Type 'typeof A' provides no match for the signature '(props: InjectedFormProps<any, {}> & { children?: ReactNode; }, context?: any): ReactElement<any>'.
答案 0 :(得分:0)
React.Component采用2种类型规范:一种用于道具,一种用于状态。如果您不使用组件状态(这是Redux的典型情况),则可以为状态传递空对象。
class A extends React.Component<AProps, {}>{
...
您可以阅读更多相关信息in the online book Hello React and Typescript, on this page.