typescript - Action> er ikke tilordnbar til parameter av typen MapDispatchToPropsParam
Jeg bruker react-redux med TypeScript, men jeg får en feil i connect-metoden.
FEIL i [at-loader] ./src/components/BodyCmp.tsx:43:73 TS2345: Argument av typen '(dispatch: any) =>() => Action>' kan ikke tildeles parameter av typen 'MapDispatchToPropsParam'. Typen '(dispatch: any) =>() => Action>' kan ikke tildeles typen 'MapDispatchToPropsFactory'. Typen '() => Action>' kan ikke tildeles typen 'MapDispatchToProps'. Typen '() => Action>' kan ikke tildeles typen 'MapDispatchToPropsFunction'. Typen 'Action>' kan ikke tildeles typen 'DispatchProps'. Egenskapen 'fetchData' mangler i typen 'Action>'.
FEIL i [at-loader] ./src/index.tsx:18:17 TS2322: Type '{}' kan ikke tildeles typen 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{ children?: ReactNode; }> & R...'. Type '{}' kan ikke tildeles typen 'Readonly'. Egenskapen 'data' mangler i typen '{}'. webpack: Klarte ikke å kompilere.
Koden er som nedenfor, takk på forhånd.
action.ts
---------------
export interface Action<T>{
type:string;
payload: T;
}
BodyCmp.tsx
------------------
import * as React from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import {fetchData} from "../Actions/userData";
import {store} from "../store/store";
import {Action} from "../models/action";
interface StateProps {
data:Array<{}>;
}
interface DispatchProps {
fetchData():Action<Promise<any>>;
}
type bodyProps = StateProps & DispatchProps;
function mapStateToProps(state:any):StateProps{
return {
data:state.dataReducer.data
};
}
function mapDispatchToProps(dispatch:any){
return bindActionCreators(fetchData, dispatch)
}
export class BodyCmp extends React.Component<bodyProps,any>{
componentDidMount() {
this.props.fetchData();
}
render(){
console.log(this.props);
return(
<div>
<h1>Bodyyyy</h1>
</div>
)
}
}
export default connect<StateProps, DispatchProps, any>(mapStateToProps, mapDispatchToProps)(BodyCmp);