作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
typescript 有错误
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>'
是否可以在没有装饰器的情况下解决这个问题? (@连接)
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)
已经尝试过使用UserProfileMain as any
但是遇到了其他一堆错误
也许你知道一些最佳实践
希望大家多多支持
最佳答案
你需要改变你的
actions: bindActionCreators(sessionActions, dispatch)
线到
actions: bindActionCreators<any>(sessionActions, dispatch)
或更具体的内容,因为 redux typescript 定义正在使用 generics .
See the redux typescript definitions here .
<>中的泛型应该是sessionActions的同类型,也是bindActionCreators()函数调用的返回值。
关于reactjs - 如何解决 typescript Redux 连接错误 ActionCreatorsMapObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42888184/
typescript 有错误 ERROR in [at-loader] ./src/app/components/profile/userProfile/_userMain.tsx:130:37
在过去的 2-3 小时内一直试图解决这个问题。该应用程序从在浏览器上运行开始,并显示错误 this.props.fetchAPOD 不是一个函数(屏幕截图位于最底部),但它显然在我的 Action 创
我是一名优秀的程序员,十分优秀!