属性 'dispatch' is missing in type error when passing root store to root component
Property 'dispatch' is missing in type error when passing root store to root component
我开始使用 typescript 和 redux,在引导我的应用程序时遇到以下错误。
Type '{ store: Store<IRootState>; }' is not assignable to type
'IntrinsicAttributes & Store<IRootState> & { children?: ReactNode; }'.
Type '{ store: Store<IRootState>; }' is not assignable to type 'Store<IRootState>'.
Property 'dispatch' is missing in type '{ store: Store<IRootState>; }'.
我正在渲染以下根组件:
const Root: React.SFC<Store<IRootState>> = (store) => (
<Provider store={store}>
<Router>
<Route exact={true} path="/" component={App} />
</Router>
</Provider>
);
ReactDOM.render(
<Root store={RootStore}/>,
//......~~~~~~~~~~~~~~~~~
document.getElementById('root') as HTMLElement
);
行store={RootStore}
中出现错误。这里 RootStore
是在我的根减速器和初始状态上调用 createStore
的结果。初始状态的类型是 IRootState
这是非常基本的:
export interface IRootState {
navBar: INavBarState;
}
根存储导出如下:
const RootStore = createStore(rootReducer, initialState);
export default RootStore;
如果我理解正确(我确定我没有理解),则会发生错误,因为参数 dispatch
不存在于 [=18 的 return 值中=].但由于这是一个库函数,我倾向于认为我在这里遗漏了一些非常明显的东西。
问题在于,对于 Root
,您将 props 声明为 Store<IRootState>
类型的对象,而不是具有 store
属性 类型 Store<IRootState>
。因此错误 '{ store: Store<IRootState>; }' is not assignable to type 'Store<IRootState>'
包装类型参数和 store
参数应该可以解决问题:
const Root: React.SFC<{store: Store<IRootState>}> = ({store}) => (
我开始使用 typescript 和 redux,在引导我的应用程序时遇到以下错误。
Type '{ store: Store<IRootState>; }' is not assignable to type
'IntrinsicAttributes & Store<IRootState> & { children?: ReactNode; }'.
Type '{ store: Store<IRootState>; }' is not assignable to type 'Store<IRootState>'.
Property 'dispatch' is missing in type '{ store: Store<IRootState>; }'.
我正在渲染以下根组件:
const Root: React.SFC<Store<IRootState>> = (store) => (
<Provider store={store}>
<Router>
<Route exact={true} path="/" component={App} />
</Router>
</Provider>
);
ReactDOM.render(
<Root store={RootStore}/>,
//......~~~~~~~~~~~~~~~~~
document.getElementById('root') as HTMLElement
);
行store={RootStore}
中出现错误。这里 RootStore
是在我的根减速器和初始状态上调用 createStore
的结果。初始状态的类型是 IRootState
这是非常基本的:
export interface IRootState {
navBar: INavBarState;
}
根存储导出如下:
const RootStore = createStore(rootReducer, initialState);
export default RootStore;
如果我理解正确(我确定我没有理解),则会发生错误,因为参数 dispatch
不存在于 [=18 的 return 值中=].但由于这是一个库函数,我倾向于认为我在这里遗漏了一些非常明显的东西。
问题在于,对于 Root
,您将 props 声明为 Store<IRootState>
类型的对象,而不是具有 store
属性 类型 Store<IRootState>
。因此错误 '{ store: Store<IRootState>; }' is not assignable to type 'Store<IRootState>'
包装类型参数和 store
参数应该可以解决问题:
const Root: React.SFC<{store: Store<IRootState>}> = ({store}) => (