我有这个React-Native代码:
// @flow
//...
interface DatasourceItem {
key: string;
isLiked: boolean;
}
type Props<T: DatasourceItem> = {
items: Array<T>,
renderItem: (T, (T) => void) => React$Node,
//...
};
type State<T: DatasourceItem> = {
items: Array<T>,
};
export default class ProductList<T: DatasourceItem> extends React.PureComponent<Props<T>,State<T>> {
constructor(props: Props<T>) {
super(props);
this.state = {
items: this.props.items,
};
}
render() {
return (
<FlatList
style={styles.list}
data={this.state.items}
renderItem={this.renderCardItem}
/>
);
}
renderCardItem = (data: { item: T }) => {
const item = data.item;
return (...);
};
}
但是我从Flow中收到以下错误:
Cannot create `FlatList` element because `DatasourceItem` [1] is incompatible with `T` [1] in property `item` of the first argument of property `renderItem`. (References: [1])flow
Cannot create `FlatList` element because `T` [1] is incompatible with `DatasourceItem` [2] in property `item` of the first argument of property `renderItem`. (References: [1] [2])flow