Merge pull request #17196 from blakeembrey/explicit-infer

[react-redux] Explicitly enable inference with `connect()`
This commit is contained in:
Mine Starks
2017-06-16 18:39:47 -07:00
committed by GitHub
2 changed files with 27 additions and 3 deletions

View File

@@ -20,7 +20,11 @@ export interface DispatchProp<S> {
}
interface ComponentDecorator<TMergedProps, TOwnProps> {
<T extends TOwnProps>(component: Component<T & TMergedProps>): ComponentClass<T>;
(component: Component<TOwnProps & TMergedProps>): ComponentClass<TOwnProps>;
}
interface ComponentDecoratorInfer<TMergedProps> {
<T>(component: Component<T & TMergedProps>): ComponentClass<T>;
}
interface ComponentMergeDecorator<TMergedProps, TOwnProps> {
@@ -46,7 +50,7 @@ interface ComponentMergeDecorator<TMergedProps, TOwnProps> {
* @param mergeProps
* @param options
*/
export declare function connect(): ComponentDecorator<DispatchProp<any>, {}>;
export declare function connect(): ComponentDecoratorInfer<DispatchProp<any>>;
export declare function connect<TStateProps, no_dispatch, TOwnProps>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps>

View File

@@ -2,7 +2,7 @@ import { Component, ReactElement } from 'react';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Store, Dispatch, bindActionCreators } from 'redux';
import { connect, Provider, DispatchProp } from 'react-redux';
import { connect, Provider, DispatchProp, MapStateToProps } from 'react-redux';
import objectAssign = require('object-assign');
//
@@ -375,6 +375,26 @@ namespace TestTOwnPropsInference {
// This should not compile, which is good.
// React.createElement(ConnectedWithTypeHint, { anything: 'goes!' });
interface AllProps {
own: string
state: string
}
class AllPropsComponent extends React.Component<AllProps & DispatchProp<any>, void> {
render() {
return <div/>;
}
}
type PickedOwnProps = Pick<AllProps, "own">
type PickedStateProps = Pick<AllProps, "state">
const mapStateToPropsForPicked: MapStateToProps<PickedStateProps, PickedOwnProps> = (state: any): PickedStateProps => {
return { state: "string" }
}
const ConnectedWithPickedOwnProps = connect(mapStateToPropsForPicked)(AllPropsComponent);
<ConnectedWithPickedOwnProps own="blah" />
}
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/16021