Skip to content
Advertisement

React-Router + Typescript error while wrapping component with Router “No overload matches this call”

I have a component that was working fine until I make a snapshot test. It says “you should not use Link outside of a Router” . Then I wrapped the component with router, but it doesn’t work. Here is the component:

JavaScript

I have @types for react-router-dom so it’s not the problem. I also tried wrapping around the component.

Also the full error is:

No overload matches this call. Overload 1 of 2, ‘(props: RouterProps | Readonly): Router’, gave the following error. Property ‘history’ is missing in type ‘{ children: Element[]; }’ but required in type ‘Readonly’. Overload 2 of 2, ‘(props: RouterProps, context: any): Router’, gave the following error. Property ‘history’ is missing in type ‘{ children: Element[]; }’ but required in type ‘Readonly’.ts(2769) index.d.ts(99, 5): ‘history’ is declared here. index.d.ts(99, 5): ‘history’ is declared here.

Advertisement

Answer

I figured it out from another question, I forgot to add my test code and didn’t mention that I’m also using Jest for testing. this is solution code:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement