diff --git a/types/react-router/v3/index.d.ts b/types/react-router/v3/index.d.ts index 2c624a63ab..c3759487da 100644 --- a/types/react-router/v3/index.d.ts +++ b/types/react-router/v3/index.d.ts @@ -13,7 +13,7 @@ // Christian Gill // Roman Nevolin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.8 +// Minimum TypeScript Version: 3.5 export { ChangeHook, diff --git a/types/react-router/v3/lib/withRouter.d.ts b/types/react-router/v3/lib/withRouter.d.ts index 69639a887f..b8c12a388a 100644 --- a/types/react-router/v3/lib/withRouter.d.ts +++ b/types/react-router/v3/lib/withRouter.d.ts @@ -7,16 +7,22 @@ interface Options { withRef?: boolean; } -export interface WithRouterProps { - location: Location; - params: Params; +export interface WithRouterProps

{ + location: Location; + params: P; router: InjectedRouter; routes: PlainRoute[]; } type ComponentConstructor

= ComponentClass

| StatelessComponent

; -declare function withRouter(component: ComponentConstructor

& S, options?: Options): ComponentClass

& S; -declare function withRouter

(component: ComponentConstructor

, options?: Options): ComponentClass

; +declare function withRouter( + component: ComponentConstructor

& S, + options?: Options +): ComponentClass> & S; +declare function withRouter

( + component: ComponentConstructor

, + options?: Options +): ComponentClass>; export default withRouter; diff --git a/types/react-router/v3/react-router-tests.tsx b/types/react-router/v3/react-router-tests.tsx index 51b9e4d4cd..f426c9eff9 100644 --- a/types/react-router/v3/react-router-tests.tsx +++ b/types/react-router/v3/react-router-tests.tsx @@ -123,19 +123,39 @@ class UserList extends React.Component { const UserListWithRouter = withRouter(UserList); +interface AvatarProps { + user: string; +} + +const Avatar: React.FunctionComponent = ({ user, children, location, params, router, routes }) => ( +

{ user }
+); + +const AvatarWithRouter = withRouter(Avatar); + type UsersProps = RouteComponentProps<{}, {}>; class Users extends React.Component { render() { const { location, params, route, routes, router, routeParams } = this.props; return
- This is a user list + This is a user list (class component with injected router props) + + This is an avatar (function component with injected router props) +
; } } -type UserProps = RouteComponentProps<{ id: string }, {}, { }, { search: string }>; +interface UserParams { + id: string; +} +interface UserQuery { + search: string; +} + +type UserProps = RouteComponentProps; class User extends React.Component { render() { @@ -214,6 +234,6 @@ const CreateHref: React.SFC = ({ router }) => ( ); -const CreateHrefWithRouter = withRouter<{}>(CreateHref); +const CreateHrefWithRouter = withRouter(CreateHref); ReactDOM.render(, document.body);