mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 15:00:26 +00:00
Add StatelessComponent<TOriginalProps> as a union type for ComponentDecorator. It allows StatelessComponents to work with the connect method signature that takes mapStateToProps and mapDispatchToProps functions.
This commit is contained in:
committed by
Masahiro Wakame
parent
15337e2b66
commit
3faa118b04
@@ -285,6 +285,37 @@ let ConnectedHelloMessage = connect()(HelloMessage);
|
||||
ReactDOM.render(<HelloMessage name="Sebastian" />, document.getElementById('content'));
|
||||
ReactDOM.render(<ConnectedHelloMessage name="Sebastian" />, document.getElementById('content'));
|
||||
|
||||
// stateless functions that uses mapStateToProps and mapDispatchToProps
|
||||
namespace TestStatelessFunctionWithMapArguments {
|
||||
interface GreetingProps {
|
||||
name: string;
|
||||
onClick: () => void;
|
||||
}
|
||||
|
||||
function Greeting(props: GreetingProps) {
|
||||
return <div>Hello {props.name}</div>;
|
||||
}
|
||||
|
||||
const mapStateToProps = (state: any, ownProps: GreetingProps) => {
|
||||
return {
|
||||
name: 'Connected! ' + ownProps.name
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch: Dispatch, ownProps: GreetingProps) => {
|
||||
return {
|
||||
onClick: () => {
|
||||
dispatch({ type: 'GREETING', name: ownProps.name });
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const ConnectedGreeting = connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(Greeting);
|
||||
}
|
||||
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/8787
|
||||
namespace TestTOwnPropsInference {
|
||||
interface OwnProps {
|
||||
|
||||
Vendored
+1
-1
@@ -11,7 +11,7 @@ declare module "react-redux" {
|
||||
import { Store, Dispatch, ActionCreator } from 'redux';
|
||||
|
||||
interface ComponentDecorator<TOriginalProps, TOwnProps> {
|
||||
(component: ComponentClass<TOriginalProps>): ComponentClass<TOwnProps>;
|
||||
(component: ComponentClass<TOriginalProps>|StatelessComponent<TOriginalProps>): ComponentClass<TOwnProps>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user