mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 12:11:47 +00:00
add withRouter decorator
This commit is contained in:
Vendored
+2
@@ -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;
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user