我有一个Typescript类的例子 . 我在'react-redux'(最后一行代码)的连接函数上有错误,我不明白为什么 . 我需要其他东西的构造函数,似乎因为它出现错误 . 有任何想法吗?
interface ITestClassProps extends IStateProps, IDispatchProps {}
interface IStateProps {
isDisabled: boolean;
}
interface IDispatchProps {
onClick: () => void;
}
class TestClass extends PureComponent<ITestClassProps, {}> {
constructor(props: ITestClassProps) {
super(props);
...
}
public render() {
return (
<div />
);
}
}
const mapStateToProps = (state: any): IStateProps => {
return {
isDisabled: state.isLoading
};
};
const mapDispatchToProps = (dispatch: any): IDispatchProps => ({
onClick: actions.onClick
});
default connect<IStateProps, IDispatchProps, {}>(
mapStateToProps,
mapDispatchToProps
)(TestClass);
错误:
[ts]
Argument of type 'typeof TestClass' is not assignable to parameter of type 'Component<IStateProps & IDispatchProps>'.
Type 'typeof TestClass' is not assignable to type 'StatelessComponent<IStateProps & IDispatchProps>'.
Type 'typeof TestClass' provides no match for the signature '(props: IStateProps & IDispatchProps & { children?: ReactNode; }, context?: any): ReactElement<any> | null'.
class TestClass
1 回答
所以看来如果我写
constructor(props?: ITestClassProps)
就行了 . 我在@types中看到构造函数的签名有props?
,也许它们之间存在冲突