I'm migrating my React project to TS and in component (I deleted most of props to simplify code):
interface Props {
activeTabIdx: number;
setActiveTab: Function;
}
const HeaderTabs = ({ activeTabIdx, setActiveTab}: Props) => {
...
};
HeaderTabs.propTypes = {
activeTabIdx: PropTypes.number.isRequired,
setActiveTab: PropTypes.func.isRequired,
};
const mapStateToProps = (state) => ({
activeTabIdx: state.tabs.activeValue,
});
const mapDispatchToProps = {
setActiveTab: _setActiveTab,
};
export default connect(mapStateToProps, mapDispatchToProps)(HeaderTabs);
On last line appears error:
Argument of type '{ ({ visible, className, activeTabIdx, setActiveTab, values }: Props): JSX.Element | null; propTypes: { values: PropTypes.Validator<any[]>; activeTabIdx: PropTypes.Validator<number>; setActiveTab: PropTypes.Validator<...>; visible: PropTypes.Validator<...>; className: PropTypes.Requireable<...>; }; defaultProps: { ....' is not assignable to parameter of type 'ComponentType<never>'.
And when I delete PropTypes
usage this error disappeares. So what can I do to make TS and PropTypes work together?
PS. I really want to remain usage of PropTypes because it can detect errors in runtime