diff --git a/types/react-redux/index.d.ts b/types/react-redux/index.d.ts index 0519a43bb5..a7f3dea705 100644 --- a/types/react-redux/index.d.ts +++ b/types/react-redux/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-redux 6.0.0 +// Type definitions for react-redux 6.0.1 // Project: https://github.com/rackt/react-redux // Definitions by: Qubo , // Thomas Hasner , @@ -54,7 +54,7 @@ interface AdvancedComponentDecorator { * - it is present in both DecorationTargetProps and InjectedProps * - DecorationTargetProps[P] extends InjectedProps[P] * ie: decorated component can accept more types than decorator is injecting - * + * * For decoration, inject props or ownProps are all optionnaly * required by the decorated (right hand side) component. * But any property required by the decorated component must extend the injected property @@ -70,9 +70,12 @@ type Shared< // Will not pass through the injected props if they are passed in during // render. Also adds new prop requirements from TNeedsProps. export interface InferableComponentEnhancerWithProps { -

>( - component: Component

- ): ComponentClass> & TNeedsProps> & {WrappedComponent: Component

} + ( + component: StatelessComponent + ): ComponentClass & {WrappedComponent: StatelessComponent} +

>( + component: Component

+ ): ComponentClass> & TNeedsProps> & {WrappedComponent: Component

} } // Injects props and removes them from the prop requirements. diff --git a/types/react-redux/react-redux-tests.tsx b/types/react-redux/react-redux-tests.tsx index ebc174dd1c..16fb7f0306 100644 --- a/types/react-redux/react-redux-tests.tsx +++ b/types/react-redux/react-redux-tests.tsx @@ -813,23 +813,42 @@ namespace TestControlledComponentWithoutDispatchProp { } namespace TestDispatchToPropsAsObject { - const onClick: ActionCreator<{}> = () => ({}); - const mapStateToProps = (state: any) => { - return { - title: state.app.title as string, - }; - }; - const dispatchToProps = { - onClick, - }; + const onClick: ActionCreator<{}> = () => ({}); + const mapStateToProps = (state: any) => { + return { + title: state.app.title as string, + }; + }; + const dispatchToProps = { + onClick, + }; - type Props = { title: string; } & typeof dispatchToProps; - const HeaderComponent: React.StatelessComponent = (props) => { - return

{props.title}

; - } + type Props = { title: string; } & typeof dispatchToProps; + const HeaderComponent: React.StatelessComponent = (props) => { + return

{props.title}

; + } - const Header = connect(mapStateToProps, dispatchToProps)(HeaderComponent); -
+ const Header = connect(mapStateToProps, dispatchToProps)(HeaderComponent); +
+} + +namespace TestInferredFunctionalComponent { + + const Header = connect( + ( + { app: { title }}: { app: { title: string }}, + { extraText }: { extraText: string } + ) => ({ + title, + extraText + }), + (dispatch) => ({ + onClick: () => dispatch({ type: 'test' }) + }) + )(({ title, extraText, onClick }) => { + return

{title} {extraText}

; + }); +
} namespace TestWrappedComponent { @@ -933,7 +952,7 @@ namespace TestWithoutTOwnPropsDecoratedInference { // This should compile React.createElement(ConnectedWithOwnPropsClass, { own: 'string', forwarded: 'string' }); React.createElement(ConnectedWithOwnPropsClass, { own: 'string', forwarded: 'string' }); - + // This should not compile, it is missing ForwardedProps React.createElement(ConnectedWithOwnPropsClass, { own: 'string' }); // $ExpectError React.createElement(ConnectedWithOwnPropsStateless, { own: 'string' }); // $ExpectError