【发布时间】:2018-03-16 14:18:23
【问题描述】:
我有以下组件
type PropTypes<T> = {
items: T[],
header: (item: T) => React.Element<*>,
body: (item: T) => React.Element<*>,
}
type StateTypes<T> = {
expandItem: ?T,
};
export default class Accordian<T> extends React.Component {
props: PropTypes<T>;
state: StateTypes<T>;
setExpandItem: (expandItem: ?T) => void;
constructor(props: PropTypes<T>) {
super(props);
...
}
}
我真的很想从items 中推断出header 的参数具有相同的类型。相反,当我用
<Accordian
items={list}
header={listItem => ...}
/>
我收到了:
-^ React element `Accordian`
20: export default class Accordian<T> extends React.Component {
^ T. This type is incompatible with.
See: src/App/components/Accordian/index.js:20
19: banks: GenericBank[],
^^^^^^^^^^^ object type
我为 TypeScript 找到了 similar question,但我想知道是否可以在 FlowType 中推断 React 元素的 props 的泛型类型?
【问题讨论】:
-
你能提供一个 flow.org/try 链接吗?我认为如果我们有更多的背景信息,我们可以更好地帮助你。 ??????
-
@MichaelDeBoey example
-
/订阅......
标签: reactjs generics jsx type-inference flowtype