react-router: Improve typing of withRouter (#15144)

* Improve typing of withRouter

Hoist typings of static methods.

* Fix declaration order

* Add test case
This commit is contained in:
('3')
2017-03-14 02:28:21 +09:00
committed by Mohamed Hegazy
parent 1f83e28d46
commit 2c98442b6f
2 changed files with 7 additions and 1 deletions

View File

@@ -6,4 +6,7 @@ interface Options {
type ComponentConstructor<P> = ComponentClass<P> | StatelessComponent<P>;
export default function withRouter<P>(component: ComponentConstructor<P>, options?: Options): ComponentClass<P>;
declare function withRouter<P, S>(component: ComponentConstructor<P> & S, options?: Options): ComponentClass<P> & S;
declare function withRouter<P>(component: ComponentConstructor<P>, options?: Options): ComponentClass<P>;
export default withRouter;

View File

@@ -81,6 +81,7 @@ interface DashboardProps {
}
class Dashboard extends React.Component<DashboardProps, {}> {
static staticMethodToBeHoisted(): void {}
navigate() {
var router = this.props.router;
@@ -102,6 +103,8 @@ class Dashboard extends React.Component<DashboardProps, {}> {
const DashboardWithRouter = withRouter(Dashboard);
DashboardWithRouter.staticMethodToBeHoisted();
class NotFound extends React.Component<{}, {}> {
render() {