1
我無法弄清楚爲什麼這個代碼構建失敗,出現以下錯誤:反應,Redux的connect()和錯誤TS2345
(43,3): error TS2345: Argument of type 'typeof Day' is not assignable to parameter of type 'Component<Props | (Props & ConnectProps & DispatchProps)>'.
Type 'typeof Day' is not assignable to type 'StatelessComponent<Props | (Props & ConnectProps & DispatchProps)>'.
Type 'typeof Day' provides no match for the signature '(props: (Props & { children?: ReactNode; }) | (Props & ConnectProps & DispatchProps & { children?: ReactNode; }), context?: any): ReactElement<any>'.
我正在打字稿2.3.3和@類型/ react-redux的版本是4.4.41。
import * as React from "react";
import { connect } from "react-redux";
export interface Props {
date: Date;
}
export interface ConnectProps {
shifts: string[];
}
export interface DispatchProps {}
class Day extends React.Component<Props & ConnectProps & DispatchProps, null> {
render() {
/* simplified */
return <div />;
}
}
const mapStateToProps = (state: any, ownProps?: Props): ConnectProps => {
/* simplified */
return {
shifts: []
};
};
const mapDispatchToProps = (dispatch: any): DispatchProps => ({});
export default connect<ConnectProps, DispatchProps, Props>(
mapStateToProps,
mapDispatchToProps
)(Day);
let component = <Day date={new Date()} />
我想避免裝飾者,只要他們是實驗性的。
請問你是如此友善,並分享一個如何使用@connect與mapstatetoprops,dispatchtoprops和一個commponent的類型安全定義的例子。我很努力。 – Karl2011