WithRouterProps types not available
See original GitHub issueAfter upgrading from Next 8.1.0 to 8.1.1 Canary the typescript type definition for WithRouterProps is not there anymore. In the previous version the following statement worked.
import { withRouter, WithRouterProps } from 'next/router';
During the 8.1.1 Canary development iteration withRouter was changed a bit. What is the approach to get those types back again.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
WithRouterProps types not available · Issue #7311 - GitHub
After upgrading from Next 8.1.0 to 8.1.1 Canary the typescript type definition for WithRouterProps is not there anymore.
Read more >issue with types when using "withRouter" and Typescript
Error arisen from types incompatibility. MenuItem is class, not type. To get type of MenuItem you should use typeof MenuItem .
Read more >How to use withRouter HOC in React Router v6 with Typescript
Complete guide on how to re-create and use withRouter HOC in React Router v6 with Typescipt.
Read more >withRouter - React Router: Declarative Routing for React.js
This means that withRouter does not re-render on route transitions unless its parent component re-renders. Static Methods and Properties. All non-react specific ...
Read more >Handle Props in React in TypeScript
In order to make illegal state unrepresentable, we can split the props into 3 types: enum Mode { easy = 'easy', medium =...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@khusamov for now you can do
I was able to update to use the new typings and wanted to share my solutions:
My component that was being wrapped by
withRouterwas previously typed withReact.FC<WithRouterProps>. I’ve updated its type to beReact.FC<{router: PublicRouterInstance}>, wherePublicRouterInstanceis a type imported fromnext/router.I was using
LinkPropsin the props definition for a component that wrappedLink, and extended the Link interface to accept additional props. My interface was something likeinterface Props extends LinkProps { ...}. This is now working usinginterface Props extends React.ComponentPropsWithoutRef<typeof Link> {...}. It’s a little more verbose, so I think there would be some value in exporting a props interface for Link (and other components) to support this pattern.If there is a better way to achieve these things, I’d be interesting in learning about them.