reactjs 浏览器路由器-类型“{子项:元素; }“与类型”IntrinsicAttributes“没有共同的属性

epggiuax  于 2022-12-18  发布在  React
关注(0)|答案(1)|浏览(355)

我已经升级了React版本到18,并从BrowserRouter组件获得一些类型错误,尝试了不同的方法,无法识别问题是什么.
下面是我调试代码时的错误,

Overload 1 of 2, '(props: BrowserRouterProps | Readonly<BrowserRouterProps>): BrowserRouter', gave the following error.
    Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<BrowserRouter> & Readonly<BrowserRouterProps>'.
  Overload 2 of 2, '(props: BrowserRouterProps, context: any): BrowserRouter', gave the following error.
    Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<BrowserRouter> & Readonly<BrowserRouterProps>'.

如果能帮上忙我会很感激的。

zhte4eai

zhte4eai1#

我在使用@types/react-router-dom@5.3.0时也遇到过类似的问题。
npm install @types/react-router-dom@5.3.3
修好了。
5.3.3版中的BrowserRouterProps接口如下所示:

export interface BrowserRouterProps {
    basename?: string | undefined;
    children?: React.ReactNode;
    getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void) | undefined;
    forceRefresh?: boolean | undefined;
    keyLength?: number | undefined;
}

并且版本5.3.0似乎没有可选的子字段。

相关问题