【发布时间】:2019-05-29 23:44:43
【问题描述】:
我正在使用带有mobx-react 的流类型作为商店的提供者。 mobx-react 使用创建 HOC 的实用函数提供存储数据:
inject('a', 'b' ....) 返回一个函数,该函数接受一个反应组件并返回一个设置了属性“a”和“b”的组件。
即:
type PropTy = {
eventStore: EventStore; //or well somewhere else set
}
inject('eventStore')(class EventView extends React.Component<PropTy>) {
render() {
return <div>this.props.eventStore.length</div>
}
}
我知道这不可能 100% 安全:无法确定“注入”(通过字符串)类型是实际类型。但现在我想忽略那部分。我希望专注于使用上述组件。 -- 在我使用这个组件流的地方“抱怨”我没有设置所有必需的属性。 (由于我没有明确设置eventStore。
所以我尝试了以下类型:
inject: <Config: {}>(...args: Array<string>) =>
((React.AbstractComponent<Config>) =>
React.AbstractComponent<$Diff<Config, args>>
),
但是,这在内部函数中与流 cannot resolve args 抱怨。 - 我将如何注释这个?
【问题讨论】:
标签: reactjs templates flowtype