Reactjs 用路由器连接错误响应ts

Reactjs 用路由器连接错误响应ts,reactjs,react-redux,react-router-v4,Reactjs,React Redux,React Router V4,我无法连接路由器和连接。 这是我得到的错误: (184,27): error TS2345: Argument of type 'ComponentClass<Pick<any, never>> & { WrappedComponent: ComponentType<any>; }' is not assignable to parameter of type 'ComponentType<RouteComponentProps<any&g

我无法连接路由器和连接。 这是我得到的错误:

(184,27): error TS2345: Argument of type 'ComponentClass<Pick<any, never>> & { WrappedComponent: ComponentType<any>; }' is not assignable to parameter of type 'ComponentType<RouteComponentProps<any>>'.
  Type 'ComponentClass<Pick<any, never>> & { WrappedComponent: ComponentType<any>; }' is not assignable to type 'StatelessComponent<RouteComponentProps<any>>'.
    Type 'ComponentClass<Pick<any, never>> & { WrappedComponent: ComponentType<any>; }' provides no match for the signature '(props: RouteComponentProps<any> & { children?: ReactNode; }, context?: any): ReactElement<any> | null'.

Shoopik在上述评论中是正确的:

withRouter
期望的类型与您传递给它的类型不匹配。我相信这是您将这些接口传递给
React.Component
的方式的结果

我不熟悉您在
MainPage
props类型(
any&RouteProps
bit)中使用的语法,但您可能希望尝试使用以下内容明确声明该接口:

export interface MainPageProps extends RouteProps{
    /* you can add additional properties in here*/
}
然后用它来声明你的
主页
类,比如:


类主页扩展React.Component

您的props接口应该扩展RouteComponentProps。传递给
RouteComponentProps
的类型变量应该描述您想要的参数

例如,如果您希望在这条路线上有两个参数(blogName和blogId)和一些道具(logo和items),那么您的完整组件道具将如下所示:

interface IProps extends RouteComponentProps<{ blogName: string, blogId: number  }> {
  className?: string
  logo?: React.ReactNode
  items?: Array<INavItem>
}
接口IProps扩展了RouteComponentProps{
类名?:字符串
logo?:React.ReactNode
项目?:数组
}
请注意下图中VSCode如何正确拾取我的参数:


这似乎是您的typescript设置中的一个类型错误?也许,我的TS设置有什么问题?我已经安装了2.6.2 TSNo,我的意思是您应该更好地查看错误,它清楚地表明您的类型不兼容。很难知道它会有什么问题,因为共享代码可能不足以准确地分析您的问题这里是代码的简单版本:
interface IProps extends RouteComponentProps<{ blogName: string, blogId: number  }> {
  className?: string
  logo?: React.ReactNode
  items?: Array<INavItem>
}