如何解决typescript Redux连接错误ActionCreatorsMapObject

Анд*_*зюк 3 compiler-errors typescript reactjs redux

打字稿有错误

ERROR in [at-loader] ./src/app/components/profile/userProfile/_userMain.tsx:130:37 
    TS2345: Argument of type 'typeof "/usr/src/app/src/js/src/app/redux/actions/sessionActions"' is not assignable to parameter of type 'ActionCreatorsMapObject'.

ERROR in [at-loader] ./src/app/components/profile/userProfile/_userMain.tsx:133:124 
    TS2345: Argument of type 'typeof UserProfileMain' is not assignable to parameter of type 'ComponentClass<(state: any) => any> | StatelessComponent<(state: any) => any>'.
  Type 'typeof UserProfileMain' is not assignable to type 'StatelessComponent<(state: any) => any>'.
    Type 'typeof UserProfileMain' provides no match for the signature '(props: ((state: any) => any) & { children?: ReactNode; }, context?: any): ReactElement<any>'
Run Code Online (Sandbox Code Playgroud)

没有装饰者可以解决这个问题吗?(@connect)

interface IActions {
    avatarUpload: (file:any) => void;
}

export interface IMainProps {
    auth: number,
    actions: IActions
}

class UserProfileMain extends React.Component<IMainProps, any> {
    constructor(props:any){
        super(props);
        this.state ={
            files: [],
        }
    }

    render(){
        return(<div />)
    }
}

const mapStateToProps = (state:any):any => {
    return {
        auth: state.authStatus.data.user.id,
    };
};

const mapDispatchToProps = (dispatch:any):any => {
    return {
        actions: bindActionCreators(sessionActions, dispatch) //First error (130:37)
    };
}
export default connect<typeof mapStateToProps, typeof mapDispatchToProps, IMainProps>(mapStateToProps, mapDispatchToProps)(UserProfileMain); //second error (133:124)
Run Code Online (Sandbox Code Playgroud)

已经尝试UserProfileMain as any但有其他一堆错误

也许你知道一些最佳实践

希望你的支持

Sgt*_*oki 7

你需要改变你的

actions: bindActionCreators(sessionActions, dispatch)
Run Code Online (Sandbox Code Playgroud)

actions: bindActionCreators<any>(sessionActions, dispatch)
Run Code Online (Sandbox Code Playgroud)

或更具体的东西,因为redux打字稿定义使用泛型.

请参阅此处的redux打字稿定义.

<>中的泛型类型应该是sessionActions的相同类型,它也是bindActionCreators()函数调用的返回值.