From da656da2633630e81f506aa8d28a4f6359e5c18e Mon Sep 17 00:00:00 2001 From: Sean Kelley Date: Thu, 31 Mar 2016 10:59:47 -0700 Subject: [PATCH] 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 2ffb30169e..22fb59a968 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 }); +}