我有一個Redux存儲並希望將其連接。這裏從我的容器成分的提取物:Redux connect(TypeScript 2)的mapStateToProps的正確類型聲明
interface IProps {
states: IAppState;
actions: IAppProps;
}
// mapping state to the props
const mapStateToProps = (state: IAppState, ownProps = {}) => ({
states: state
});
// mapping actions to the props
const mapDispatchToProps = (dispatch: Redux.Dispatch<IAppState>) => ({
actions: Redux.bindActionCreators(actions, dispatch)
});
// connect store to App
@connect<IAppState, IAppProps, any>(
mapStateToProps,
mapDispatchToProps
)
export default class App extends React.Component<IProps, {}> {
//...
}
編譯時我收到了以下問題:我使用的是
error TS2345: Argument of type '(state: IAppState, ownProps?: {}) => { states: IAppState; }' is not assignable to parameter of type 'MapStateToPropsParam<IAppState, any>'.
Type '(state: IAppState, ownProps?: {}) => { states: IAppState; }' is not assignable to type 'MapStateToPropsFactory<IAppState, any>'.
Type '{ states: IAppState; }' is not assignable to type 'MapStateToProps<IAppState, any>'.
Type '{ states: IAppState; }' provides no match for the signature '(state: any, ownProps?: any): IAppState'.
@類型/反應,終極版@ 44年4月4日暴露MapStateToProps接口。我會認爲我的mapStateToProps面對這個接口...然而有些事情是錯誤的。任何想法是什麼?
謝謝你的概念,但它並沒有解決我的問題:( –
嗯這是奇怪的例外看,它看起來像打字稿不喜歡你如何定義'狀態'。試着看看那個...... – Ematipico