![](/img/trans.png)
[英]Property 'x' is missing in type '{}' but required in type 'Pick<Interface, "x">'. TS2741
[英]Property 'X' is missing in type 'DefaultRootState' - but the property is declared in Interface
这是我与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;
}
这是mapStateToProps
fn 表达式:
const mapStateToProps = (state: IStore) => ({
store: {
IModal: state.userPrefs.IModal,
},
});
这是connect
HOC:
export default connect<IStore,{}>(mapStateToProps, mapDispatchToProps)(IModal);
我可以通过以下方式解决这个问题:
export default connect<IStore>(mapStateToProps as any, mapDispatchToProps)(IModal);
但我正试图找到一个通用的解决方案
只需从connect
调用中删除类型并让 typescript 为您处理它:
connect(mapStateToProps, mapDispatchToProps)(FingerprintModal);
否则,您将需要指定完整类型:
connect<{store: IStore;}, {}, {}, IStore>(mapStateToProps, mapDispatchToProps)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.