react-router.d.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // React 18 removed children from ComponentType, this adds them back
  10. interface RouteProps {
  11. children?: ReactNode;
  12. }
  13. interface InjectedRouter<P = Record<string, string>, Q = any> {
  14. location: Location<Q>;
  15. params: P;
  16. routes: PlainRoute[];
  17. }
  18. interface WithRouterProps<P = Record<string, string>, Q = any> {
  19. location: Location<Q>;
  20. params: P;
  21. router: InjectedRouter<P, Q>;
  22. routes: PlainRoute[];
  23. }
  24. interface RouteContextInterface {
  25. location: Location<Q>;
  26. params: P;
  27. router: InjectedRouter<P, Q>;
  28. routes: PlainRoute[];
  29. }
  30. type ComponentConstructor<P> =
  31. | ComponentClass<P>
  32. | FunctionComponent<P>
  33. | ComponentType<P>;
  34. declare function withRouter<P extends WithRouterProps>(
  35. component: ComponentConstructor<P>,
  36. options?: Options
  37. ): ComponentClass<Omit<P, keyof WithRouterProps>>;
  38. declare function withRouter<P extends WithRouterProps, S>(
  39. component: ComponentConstructor<P> & S,
  40. options?: Options
  41. ): ComponentClass<Omit<P, keyof WithRouterProps>> & S;
  42. }