【发布时间】:2019-06-13 11:44:05
【问题描述】:
我编写了一个包装器,通过注入 store prop 将组件连接到 store。包装器代码工作正常并通过测试。
import React, { ComponentType } from 'react';
import store from './index';
import { RootStore } from './RootStore';
interface InjectedStoreProps {
store: RootStore;
}
const withStore = (WrappedComponent: ComponentType<InjectedStoreProps>) => {
const output = ({...props}) => <WrappedComponent store={store} {...props} />;
return output;
}
export default withStore;
但是,在我的一项测试中,我有
const ComponentToWrap = withStore(
({store, otherProp}) => (
<div>
<span>
{store}
</span>
<span>
{otherProp}
</span>
</div>
)
);
导致打字稿错误Type 'PropsWithChildren<InjectedStoreProps>' has no property 'otherProp' and no string index signature.
我是打字稿的新手,所以肯定会误解一些东西。我尝试了许多谷歌搜索的东西,但没有一个有帮助。
反应 v16.8.6 打字稿 v3.4.3
【问题讨论】:
标签: reactjs typescript higher-order-functions