react-router.d.ts 1.3 KB

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