2

I created an array of properties for a routes

const routes: RouteProps[] = [
  {
    path: '/',
    exact: true,
    component: Main,
  },
];

and created a separate routing switch component

const Routes: FunctionComponent = (): JSX.Element => {
  return (
    <Switch>
      {
        routes.map((props: RouteProps, idx: number) => <Router key={idx} {...props} />)
      }
    </Switch>
  );
};

But I get an error:
Error:(10, 57) TS2769: No overload matches this call.
Overload 1 of 2, '(props: Readonly): Router', gave the following error.
Property 'history' is missing in type '{ location?: Location | undefined; component?: ComponentClass, any> | FunctionComponent> | ComponentClass<...> | FunctionComponent<...> | undefined; ... 6 more ...; key: number; }' but required in type 'Readonly'.
Overload 2 of 2, '(props: RouterProps, context?: any): Router', gave the following error.
Property 'history' is missing in type '{ location?: Location | undefined; component?: ComponentClass, any> | FunctionComponent> | ComponentClass<...> | FunctionComponent<...> | undefined; ... 6 more ...; key: number; }' but required in type 'Readonly'.

  • How happens when wrapping your `RouterProps` with `Partial` like `const routes: Partial[] = [` – Gompro Sep 09 '19 at 02:43

0 Answers0