mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 05:20:24 +08:00
Add a test for the issue discussed in #8787.
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user