How to add type check for history object in React?

Posted by Jessica Taylor | Updated on

Want to add type check for history object in React? You can use the RouteComponentProps interface, which declares all props passed by withRouter:

The type parameter to RouteComponentProps is the type of the params property in match, so you won’t need it unless you’re matching named path segments.

Alternatively, if history doesn’t come from withRouter but is passed by itself as a prop, you can import the type from history:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers