繁体   English   中英

“DefaultRootState”类型中缺少属性“X”-但该属性是在接口中声明的

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM