From 2c98442b6fc66b6d378564f44c77e0e4851f6a2d Mon Sep 17 00:00:00 2001 From: "('3')" Date: Tue, 14 Mar 2017 02:28:21 +0900 Subject: [PATCH] react-router: Improve typing of withRouter (#15144) * Improve typing of withRouter Hoist typings of static methods. * Fix declaration order * Add test case --- react-router/lib/withRouter.d.ts | 5 ++++- react-router/react-router-tests.tsx | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/react-router/lib/withRouter.d.ts b/react-router/lib/withRouter.d.ts index 25f9d357c7..209c01f913 100644 --- a/react-router/lib/withRouter.d.ts +++ b/react-router/lib/withRouter.d.ts @@ -6,4 +6,7 @@ interface Options { type ComponentConstructor

= ComponentClass

| StatelessComponent

; -export default 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/react-router/react-router-tests.tsx b/react-router/react-router-tests.tsx index 8d7fd05178..314c78c6ce 100644 --- a/react-router/react-router-tests.tsx +++ b/react-router/react-router-tests.tsx @@ -81,6 +81,7 @@ interface DashboardProps { } class Dashboard extends React.Component { + static staticMethodToBeHoisted(): void {} navigate() { var router = this.props.router; @@ -102,6 +103,8 @@ class Dashboard extends React.Component { const DashboardWithRouter = withRouter(Dashboard); +DashboardWithRouter.staticMethodToBeHoisted(); + class NotFound extends React.Component<{}, {}> { render() {