typescript 如何修复React JS中的以下TS2345错误?

5cg8jx4n  于 2023-03-09  发布在  TypeScript
关注(0)|答案(1)|浏览(206)

我将修复开发react js时引起的错误

//router/routes.tsx file
interface AppRoute {
  path?: string;
  index?: boolean;
  element?: JSX.Element;
  nestedRoutes?: AppRoute[];
}
export const dashboardRoutes: AppRoute[] = [
  {
    path: PRIVATE_ROUTE_PATHS.home,
    element: <PanelLayout />,
    nestedRoutes: [
      { index: true, path: PRIVATE_ROUTE_PATHS.home, element: <Dashboard /> },
      { path: PRIVATE_ROUTE_PATHS.contacts, element: <Contact /> },
      { path: PRIVATE_ROUTE_PATHS.contactDetail, element: <ContactDetail /> },
    ],
  },
];

//mian.tsx
import { dashboardRoutes } from 'router/routes';
import useBreadcrumbs from 'use-react-router-breadcrumbs';

const breadcrumbs = useBreadcrumbs(dashboardRoutes); //error

以下错误导致最后一行代码:TS2345: Argument of type 'AppRoute[]' is not assignable to parameter of type 'BreadcrumbsRoute<string>[]'. Type 'AppRoute' has no properties in common with type 'BreadcrumbsRoute<string>'.
请帮助我修复此错误

68bkxrlz

68bkxrlz1#

这非常简单,首先你需要查看你用作参数的变量的类型。
dashboardRoutes的类型为AppRoute[]
useBreadcrumbs仅接受BreadcrumbsRoute<string>作为参数。
您只是传入了不正确的数据类型。

相关问题