[英]Property 'X' is missing in type 'DefaultRootState' - but the property is declared in Interface
Here's my Interface which I'm using with mapStateToProps
:这是我与
mapStateToProps
使用的接口:
export interface IStore {
cache?: any;
dataManager?: IUR;
userPrefs: IUP;
IModal?: IfingerprintModal;
}
export interface IModal {
cbCancel: IFModalFn | null;
cbTryAgain?: IFModalFn | null;
error: null | string;
success: boolean;
visible: boolean;
}
Here's the mapStateToProps
fn expression:这是
mapStateToProps
fn 表达式:
const mapStateToProps = (state: IStore) => ({
store: {
IModal: state.userPrefs.IModal,
},
});
And here's the connect
HOC:这是
connect
HOC:
export default connect<IStore,{}>(mapStateToProps, mapDispatchToProps)(IModal);
That's the error I'm seeing:这就是我看到的错误:
I can get rid of the problem by:我可以通过以下方式解决这个问题:
export default connect<IStore>(mapStateToProps as any, mapDispatchToProps)(IModal);
But I am trying to find a generic solution to that但我正试图找到一个通用的解决方案
Just remove the type from the connect
call and let typescript to handle it for you:只需从
connect
调用中删除类型并让 typescript 为您处理它:
connect(mapStateToProps, mapDispatchToProps)(FingerprintModal);
Otherwise you would need to specify the full type:否则,您将需要指定完整类型:
connect<{store: IStore;}, {}, {}, IStore>(mapStateToProps, mapDispatchToProps)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.