Merge pull request #15929 from thasner/react-redux/connect

`react-redux` `ComponentDecorator` input accepts `TOwnProps`
This commit is contained in:
Ryan Cavanaugh
2017-04-19 11:03:07 -07:00
committed by GitHub
2 changed files with 13 additions and 12 deletions
+11 -10
View File
@@ -1,6 +1,6 @@
// Type definitions for react-redux 4.4.0
// Project: https://github.com/rackt/react-redux
// Definitions by: Qubo <https://github.com/tkqubo>, Sean Kelley <https://github.com/seansfkelley>
// Definitions by: Qubo <https://github.com/tkqubo>, Sean Kelley <https://github.com/seansfkelley>, Thomas Hasner <https://github.com/thasner>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
@@ -9,13 +9,14 @@ import * as Redux from 'redux';
type ComponentClass<P> = React.ComponentClass<P>;
type StatelessComponent<P> = React.StatelessComponent<P>;
type Component<P> = ComponentClass<P> | StatelessComponent<P>;
type ReactNode = React.ReactNode;
type Store<S> = Redux.Store<S>;
type Dispatch<S> = Redux.Dispatch<S>;
type ActionCreator<A> = Redux.ActionCreator<A>;
interface ComponentDecorator<TOriginalProps, TOwnProps> {
(component: ComponentClass<TOriginalProps> | StatelessComponent<TOriginalProps>): ComponentClass<TOwnProps>;
interface ComponentDecorator<TStateProps, TDispatchProps, TOwnProps> {
(component: Component<TStateProps & TDispatchProps & TOwnProps>): ComponentClass<TOwnProps>;
}
/**
@@ -23,8 +24,8 @@ interface ComponentDecorator<TOriginalProps, TOwnProps> {
*
* Can't use the above decorator because it would default the type to {}
*/
export interface InferableComponentDecorator {
<P, TComponentConstruct extends (ComponentClass<P> | StatelessComponent<P>)>(component: TComponentConstruct): TComponentConstruct;
export interface InferableComponentDecorator<TOwnProps> {
<T extends Component<TOwnProps>>(component: T): T;
}
/**
@@ -46,14 +47,14 @@ export interface InferableComponentDecorator {
* @param mergeProps
* @param options
*/
export declare function connect(): InferableComponentDecorator;
export declare function connect<TOwnProps>(): InferableComponentDecorator<TOwnProps>;
export declare function connect<TStateProps, TDispatchProps, TOwnProps>(
mapStateToProps?: MapStateToProps<TStateProps, TOwnProps> | MapStateToPropsFactory<TStateProps, TOwnProps>,
mapDispatchToProps?: MapDispatchToProps<TDispatchProps, TOwnProps> | MapDispatchToPropsFactory<TDispatchProps, TOwnProps>,
mergeProps?: MergeProps<TStateProps, TDispatchProps, TOwnProps>,
options?: Options
): ComponentDecorator<TStateProps & TDispatchProps, TOwnProps>;
): ComponentDecorator<TStateProps, TDispatchProps, TOwnProps>;
interface MapStateToProps<TStateProps, TOwnProps> {
(state: any, ownProps?: TOwnProps): TStateProps;
@@ -92,9 +93,9 @@ interface Options {
*/
pure?: boolean;
/**
* If true, stores a ref to the wrapped component instance and makes it available via
* getWrappedInstance() method. Defaults to false.
*/
* If true, stores a ref to the wrapped component instance and makes it available via
* getWrappedInstance() method. Defaults to false.
*/
withRef?: boolean;
}
+2 -2
View File
@@ -343,7 +343,7 @@ namespace TestTOwnPropsInference {
state: string;
}
class OwnPropsComponent extends React.Component<OwnProps & StateProps, {}> {
class OwnPropsComponent extends React.Component<OwnProps & StateProps, void> {
render() {
return <div/>;
}
@@ -359,7 +359,7 @@ namespace TestTOwnPropsInference {
const ConnectedWithoutOwnProps = connect(mapStateToPropsWithoutOwnProps)(OwnPropsComponent);
const ConnectedWithOwnProps = connect(mapStateToPropsWithOwnProps)(OwnPropsComponent);
const ConnectedWithTypeHint = connect<StateProps, {}, OwnProps>(mapStateToPropsWithoutOwnProps)(OwnPropsComponent);
const ConnectedWithTypeHint = connect<StateProps, void, OwnProps>(mapStateToPropsWithoutOwnProps)(OwnPropsComponent);
// This compiles, which is bad.
React.createElement(ConnectedWithoutOwnProps, { anything: 'goes!' });