From 52371a816d7c1d406e28c6d83b48ab6bc9be8583 Mon Sep 17 00:00:00 2001 From: Thomas Hasner Date: Mon, 17 Apr 2017 21:13:24 -0400 Subject: [PATCH 1/3] `ComponentDecorator` input accepts `TOwnProps` --- types/react-redux/index.d.ts | 20 ++++++-------------- types/react-redux/react-redux-tests.tsx | 4 ++-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/types/react-redux/index.d.ts b/types/react-redux/index.d.ts index 1f300e02a6..ac48c13f44 100644 --- a/types/react-redux/index.d.ts +++ b/types/react-redux/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for react-redux 4.4.0 // Project: https://github.com/rackt/react-redux -// Definitions by: Qubo , Sean Kelley +// Definitions by: Qubo , Sean Kelley , Thomas Hasner // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 @@ -9,22 +9,14 @@ import * as Redux from 'redux'; type ComponentClass

= React.ComponentClass

; type StatelessComponent

= React.StatelessComponent

; +type Component

= ComponentClass

| StatelessComponent

; type ReactNode = React.ReactNode; type Store = Redux.Store; type Dispatch = Redux.Dispatch; type ActionCreator = Redux.ActionCreator; -interface ComponentDecorator { - (component: ComponentClass | StatelessComponent): ComponentClass; -} - -/** - * Decorator that infers the type from the original component - * - * Can't use the above decorator because it would default the type to {} - */ -export interface InferableComponentDecorator { - | StatelessComponent

)>(component: TComponentConstruct): TComponentConstruct; +interface ComponentDecorator { + (component: Component): ComponentClass; } /** @@ -46,14 +38,14 @@ export interface InferableComponentDecorator { * @param mergeProps * @param options */ -export declare function connect(): InferableComponentDecorator; +export declare function connect(): ComponentDecorator; export declare function connect( mapStateToProps?: MapStateToProps | MapStateToPropsFactory, mapDispatchToProps?: MapDispatchToProps | MapDispatchToPropsFactory, mergeProps?: MergeProps, options?: Options -): ComponentDecorator; +): ComponentDecorator; interface MapStateToProps { (state: any, ownProps?: TOwnProps): TStateProps; diff --git a/types/react-redux/react-redux-tests.tsx b/types/react-redux/react-redux-tests.tsx index 4c7a55ea7b..2456f2a379 100644 --- a/types/react-redux/react-redux-tests.tsx +++ b/types/react-redux/react-redux-tests.tsx @@ -343,7 +343,7 @@ namespace TestTOwnPropsInference { state: string; } - class OwnPropsComponent extends React.Component { + class OwnPropsComponent extends React.Component { render() { return

; } @@ -359,7 +359,7 @@ namespace TestTOwnPropsInference { const ConnectedWithoutOwnProps = connect(mapStateToPropsWithoutOwnProps)(OwnPropsComponent); const ConnectedWithOwnProps = connect(mapStateToPropsWithOwnProps)(OwnPropsComponent); - const ConnectedWithTypeHint = connect(mapStateToPropsWithoutOwnProps)(OwnPropsComponent); + const ConnectedWithTypeHint = connect(mapStateToPropsWithoutOwnProps)(OwnPropsComponent); // This compiles, which is bad. React.createElement(ConnectedWithoutOwnProps, { anything: 'goes!' }); From 5f0393494077fcf04b914d87ce58892dc4234a3f Mon Sep 17 00:00:00 2001 From: Tom Hasner Date: Mon, 17 Apr 2017 22:57:58 -0400 Subject: [PATCH 2/3] fix --- types/react-redux/index.d.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/types/react-redux/index.d.ts b/types/react-redux/index.d.ts index ac48c13f44..6eec9147a0 100644 --- a/types/react-redux/index.d.ts +++ b/types/react-redux/index.d.ts @@ -19,6 +19,15 @@ interface ComponentDecorator { (component: Component): ComponentClass; } +/** + * Decorator that infers the type from the original component + * + * Can't use the above decorator because it would default the type to {} + */ +export interface InferableComponentDecorator { + >(component: T): T; +} + /** * Connects a React component to a Redux store. * @@ -38,7 +47,7 @@ interface ComponentDecorator { * @param mergeProps * @param options */ -export declare function connect(): ComponentDecorator; +export declare function connect(): InferableComponentDecorator; export declare function connect( mapStateToProps?: MapStateToProps | MapStateToPropsFactory, @@ -84,9 +93,9 @@ interface Options { */ pure?: boolean; /** - * If true, stores a ref to the wrapped component instance and makes it available via - * getWrappedInstance() method. Defaults to false. - */ + * If true, stores a ref to the wrapped component instance and makes it available via + * getWrappedInstance() method. Defaults to false. + */ withRef?: boolean; } From 416c0f9c3df391ca24139d18f750506edd3180ce Mon Sep 17 00:00:00 2001 From: Thomas Hasner Date: Tue, 18 Apr 2017 13:51:36 -0400 Subject: [PATCH 3/3] Use `TOwnProps` instead of `IOwnProps` --- types/react-redux/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/react-redux/index.d.ts b/types/react-redux/index.d.ts index 6eec9147a0..dc85bc86eb 100644 --- a/types/react-redux/index.d.ts +++ b/types/react-redux/index.d.ts @@ -24,8 +24,8 @@ interface ComponentDecorator { * * Can't use the above decorator because it would default the type to {} */ -export interface InferableComponentDecorator { - >(component: T): T; +export interface InferableComponentDecorator { + >(component: T): T; } /**