问题描述
当我使用static propTypes和typeScript和connect时,typeScript的类型校验就报错了.
告诉我类型丢了
问题出现的环境背景及自己尝试过哪些方法
我是ts新手.并没有搜索到有用的解决方法
相关代码
import React, {PureComponent} from 'react';
import { withRouter } from 'react-router';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { RootState } from '../../../reducers';
type IProps = {
title: string;
} & ReturnType<typeof mapStateToProps>
class Test extends PureComponent<IProps> {
static propTypes = {
title: PropTypes.string
}
render() {
const { title } = this.props;
return (
<div>hello world! {title}</div>
)
}
}
const mapStateToProps = (state: RootState) => {
return {
state
}
}
export default
connect(mapStateToProps)(Test)
`
你期待的结果是什么?实际看到的错误信息又是什么?
'Argument of type 'typeof Test' is not assignable to parameter of type 'ComponentType<never>'.
Type 'typeof Test' is not assignable to type 'ComponentClass<never, any>'.
Types of property 'propTypes' are incompatible.
Type '{ title: Requireable<string>; }' is not assignable to type 'undefined'.