簡體   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