From 6694581d3ed54e9009b2b95f555e6b61f0e0a897 Mon Sep 17 00:00:00 2001 From: Sean Kelley Date: Thu, 31 Mar 2016 10:39:04 -0700 Subject: [PATCH 1/4] react-redux: remove React.Props references because it is deprecated. --- react-redux/react-redux.d.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/react-redux/react-redux.d.ts b/react-redux/react-redux.d.ts index 89d33cf6d..ec1bded47 100644 --- a/react-redux/react-redux.d.ts +++ b/react-redux/react-redux.d.ts @@ -7,10 +7,10 @@ /// declare module "react-redux" { - import { ComponentClass, Component, StatelessComponent, Props, ReactNode } from 'react'; + import { ComponentClass, Component, StatelessComponent, ReactNode } from 'react'; import { Store, Dispatch, ActionCreator } from 'redux'; - interface ComponentDecorator, TOwnProps extends Props> { + interface ComponentDecorator { (component: ComponentClass): ComponentClass; } @@ -43,19 +43,13 @@ declare module "react-redux" { * @param options */ export function connect(): InferableComponentDecorator; - export function connect< - TStateProps extends Props, - TDispatchProps extends Props, - TOwnProps extends Props - >( + + export function connect( mapStateToProps: MapStateToProps, mapDispatchToProps?: MapDispatchToPropsFunction|MapDispatchToPropsObject ): ComponentDecorator; - export function connect< - TStateProps extends Props, - TDispatchProps extends Props, - TOwnProps extends Props - >( + + export function connect( mapStateToProps: MapStateToProps, mapDispatchToProps: MapDispatchToPropsFunction|MapDispatchToPropsObject, mergeProps: MergeProps, @@ -89,7 +83,7 @@ declare module "react-redux" { pure: boolean; } - export interface ProviderProps extends Props { + export interface ProviderProps { /** * The single Redux store in your application. */ From da656da2633630e81f506aa8d28a4f6359e5c18e Mon Sep 17 00:00:00 2001 From: Sean Kelley Date: Thu, 31 Mar 2016 10:59:47 -0700 Subject: [PATCH 2/4] Add a test for the issue discussed in #8787. --- react-redux/react-redux-tests.tsx | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/react-redux/react-redux-tests.tsx b/react-redux/react-redux-tests.tsx index 2ffb30169..22fb59a96 100644 --- a/react-redux/react-redux-tests.tsx +++ b/react-redux/react-redux-tests.tsx @@ -284,3 +284,47 @@ function HelloMessage(props: HelloMessageProps) { let ConnectedHelloMessage = connect()(HelloMessage); ReactDOM.render(, document.getElementById('content')); ReactDOM.render(, document.getElementById('content')); + +// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/8787 +namespace TestTOwnPropsInference { + interface OwnProps { + own: string; + } + + interface StateProps { + state: string; + } + + class OwnPropsComponent extends React.Component { + render() { + return null; + } + } + + function mapStateToPropsWithoutOwnProps(state: any): StateProps { + return { state: 'string' }; + } + + function mapStateToPropsWithOwnProps(state: any, ownProps: OwnProps): StateProps { + return { state: 'string' }; + } + + const ConnectedWithoutOwnProps = connect(mapStateToPropsWithoutOwnProps)(OwnPropsComponent); + const ConnectedWithOwnProps = connect(mapStateToPropsWithOwnProps)(OwnPropsComponent); + const ConnectedWithTypeHint = connect(mapStateToPropsWithoutOwnProps)(OwnPropsComponent); + + // This compiles, which is bad. + React.createElement(ConnectedWithoutOwnProps, { anything: 'goes!' }); + + // This compiles, as expected. + React.createElement(ConnectedWithOwnProps, { own: 'string' }); + + // This should not compile, which is good. + // React.createElement(ConnectedWithOwnProps, { missingOwn: true }); + + // This compiles, as expected. + React.createElement(ConnectedWithTypeHint, { own: 'string' }); + + // This should not compile, which is good. + // React.createElement(ConnectedWithTypeHint, { missingOwn: true }); +} From 231f8eadc168da7e698e360a7199c29a9335a8f1 Mon Sep 17 00:00:00 2001 From: Sean Kelley Date: Thu, 31 Mar 2016 11:01:07 -0700 Subject: [PATCH 3/4] react-redux: add myself as maintainer cause I've been noodling this stuff a lot --- react-redux/react-redux.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-redux/react-redux.d.ts b/react-redux/react-redux.d.ts index ec1bded47..0e7810e35 100644 --- a/react-redux/react-redux.d.ts +++ b/react-redux/react-redux.d.ts @@ -1,6 +1,6 @@ // Type definitions for react-redux 4.4.0 // Project: https://github.com/rackt/react-redux -// Definitions by: Qubo +// Definitions by: Qubo , Sean Kelley // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// From 8a7d208e0dcb37d4f62588eeef2cd71b5b8bff98 Mon Sep 17 00:00:00 2001 From: Sean Kelley Date: Thu, 31 Mar 2016 11:06:38 -0700 Subject: [PATCH 4/4] react-redux: Fix compilation error for dumb reason. --- react-redux/react-redux-tests.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-redux/react-redux-tests.tsx b/react-redux/react-redux-tests.tsx index 22fb59a96..4158a035e 100644 --- a/react-redux/react-redux-tests.tsx +++ b/react-redux/react-redux-tests.tsx @@ -297,7 +297,7 @@ namespace TestTOwnPropsInference { class OwnPropsComponent extends React.Component { render() { - return null; + return
; } }