react-router.d.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import type {ComponentClass, ComponentType, StatelessComponent} from 'react';
  2. import type {InjectedRouter, PlainRoute, WithRouterProps} from 'react-router';
  3. import type {Location} from 'history';
  4. declare module 'react-router' {
  5. interface InjectedRouter<P = Record<string, string>, Q = any> {
  6. location: Location<Q>;
  7. params: P;
  8. routes: PlainRoute[];
  9. }
  10. interface WithRouterProps<P = Record<string, string>, Q = any> {
  11. location: Location<Q>;
  12. params: P;
  13. router: InjectedRouter<P, Q>;
  14. routes: PlainRoute[];
  15. }
  16. interface RouteContextInterface {
  17. location: Location<Q>;
  18. params: P;
  19. router: InjectedRouter<P, Q>;
  20. routes: PlainRoute[];
  21. }
  22. type ComponentConstructor<P> =
  23. | ComponentClass<P>
  24. | StatelessComponent<P>
  25. | ComponentType<P>;
  26. declare function withRouter<P extends WithRouterProps>(
  27. component: ComponentConstructor<P>,
  28. options?: Options
  29. ): ComponentClass<Omit<P, keyof WithRouterProps>>;
  30. declare function withRouter<P extends WithRouterProps, S>(
  31. component: ComponentConstructor<P> & S,
  32. options?: Options
  33. ): ComponentClass<Omit<P, keyof WithRouterProps>> & S;
  34. }