From 1d8a7055cf825e3a2b63147f4186e359e5b23acd Mon Sep 17 00:00:00 2001 From: Egor Shulga Date: Wed, 9 Aug 2017 15:03:53 +0300 Subject: [PATCH] add withRouter decorator --- types/react-router/index.d.ts | 2 ++ .../react-router/test/WithRouterDecorator.tsx | 19 +++++++++++++++++++ types/react-router/tsconfig.json | 6 ++++-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 types/react-router/test/WithRouterDecorator.tsx diff --git a/types/react-router/index.d.ts b/types/react-router/index.d.ts index 82811fadfb..a15005bc78 100644 --- a/types/react-router/index.d.ts +++ b/types/react-router/index.d.ts @@ -13,6 +13,7 @@ // Huy Nguyen // Jérémy Fauvel // Daniel Roth +// Egor Shulga // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -100,3 +101,4 @@ export interface match

{ export function matchPath

(pathname: string, props: RouteProps): match

| null; export function withRouter

(component: React.ComponentType & P>): React.ComponentClass

; +export function withRouter>(target: TFunction): TFunction; // decorator signature diff --git a/types/react-router/test/WithRouterDecorator.tsx b/types/react-router/test/WithRouterDecorator.tsx new file mode 100644 index 0000000000..6d87de2e6b --- /dev/null +++ b/types/react-router/test/WithRouterDecorator.tsx @@ -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 { + render() { + return ( +

Welcome {this.props.username}

+ ); + } +} + +const WithRouterTest = () => (); + +export default WithRouterTest; diff --git a/types/react-router/tsconfig.json b/types/react-router/tsconfig.json index 7e6466a83c..f609cbf859 100644 --- a/types/react-router/tsconfig.json +++ b/types/react-router/tsconfig.json @@ -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" ] }