![](/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.