React
在使用TS+react-router-dom
中的withRouter
方法报错问题
解决文章地址
问题描述
类型“FC<ISideBar>”的参数不能赋给类型“ComponentType<RouteComponentProps<any, StaticContext, unknown>>”的参数。
不能将类型“FunctionComponent<ISideBar>”分配给类型“FunctionComponent<RouteComponentProps<any, StaticContext, unknown>>”。
属性“propTypes”的类型不兼容。
不能将类型“WeakValidationMap<ISideBar> | undefined”分配给类型“WeakValidationMap<RouteComponentProps<any, StaticContext, unknown>> | undefined”。
类型“WeakValidationMap<ISideBar>”与类型“WeakValidationMap<RouteComponentProps<any, StaticContext, unknown>>”不具有相同的属性。
- 直接在声明的
interface
接口中继承RouteComponentProps
import { useHistory, withRouter, RouteComponentProps } from 'react-router-dom'
interface ISideBar extends RouteComponentProps {
sideStatus?: boolean
}