type TestProps<T> = {
item: T,
onSelect: (item:T) => void,
};
const B = <T>(props:TestProps<T>) => {
// ...
};
class A<T> extends React.Component<TestProps<T>> {
render() {
return (
<B
item={this.props.item}
// ^^^^^^^^^^^^^^^ T. This type is incompatible with the expected param type of
onSelect={this.onSelect}
/>
);
};
onSelect = (item:T) => {
// ^ some incompatible instantiation of `T`
this.props.onSelect(item);
};
}
Please look at following code:
👉 Try it
Seems that the error caused by class instance field
onSelect
.The only workaround I found is to pass
this.onSelect.bind(this)
in render method and don't useonSelect = () => {}
syntax:👉 Try it