add withRouter decorator

This commit is contained in:
Egor Shulga
2017-08-09 15:03:53 +03:00
parent 825d361b8e
commit 1d8a7055cf
3 changed files with 25 additions and 2 deletions
+2
View File
@@ -13,6 +13,7 @@
// Huy Nguyen <https://github.com/huy-nguyen>
// Jérémy Fauvel <https://github.com/grmiade>
// Daniel Roth <https://github.com/DaIgeb>
// Egor Shulga <https://github.com/egorshulga>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -100,3 +101,4 @@ export interface match<P> {
export function matchPath<P>(pathname: string, props: RouteProps): match<P> | null;
export function withRouter<P>(component: React.ComponentType<RouteComponentProps<any> & P>): React.ComponentClass<P>;
export function withRouter<P, TFunction extends React.ComponentClass<P>>(target: TFunction): TFunction; // decorator signature
@@ -0,0 +1,19 @@
import * as React from 'react';
import { withRouter, RouteComponentProps } from 'react-router-dom';
interface TOwnProps {
username: string;
}
@withRouter
class Component extends React.Component<TOwnProps, {}> {
render() {
return (
<h2>Welcome {this.props.username}</h2>
);
}
}
const WithRouterTest = () => (<Component username="John" />);
export default WithRouterTest;
+4 -2
View File
@@ -10,7 +10,8 @@
"noImplicitAny": true,
"noImplicitThis": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true
"noEmit": true,
"experimentalDecorators": true
},
"files": [
"index.d.ts",
@@ -34,6 +35,7 @@
"test/MemoryRouter.tsx",
"test/Switch.tsx",
"test/InheritingRoute.tsx",
"test/WithRouter.tsx"
"test/WithRouter.tsx",
"test/WithRouterDecorator.tsx"
]
}