Add a test for the issue discussed in #8787.

This commit is contained in:
Sean Kelley
2016-03-31 10:59:47 -07:00
parent 6694581d3e
commit da656da263

View File

@@ -284,3 +284,47 @@ function HelloMessage(props: HelloMessageProps) {
let ConnectedHelloMessage = connect()(HelloMessage);
ReactDOM.render(<HelloMessage name="Sebastian" />, document.getElementById('content'));
ReactDOM.render(<ConnectedHelloMessage name="Sebastian" />, 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<OwnProps & StateProps, {}> {
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<StateProps, {}, OwnProps>(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 });
}