react-redux: correct mapDispatchToProps param type (#34498)

* react-redux: correct `mapDispatchToProps` param type

Fixes https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34493

* Complete explanation

* Move test
This commit is contained in:
Oliver Joseph Ash
2019-04-19 08:44:41 -07:00
committed by Benjamin Lichtman
parent 03186dbc08
commit e4f661ba43
2 changed files with 33 additions and 8 deletions
+4 -4
View File
@@ -171,7 +171,7 @@ export interface Connect {
<no_state = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
mapDispatchToProps: TDispatchProps,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
): InferableComponentEnhancerWithProps<
ResolveThunks<TDispatchProps>,
TOwnProps
@@ -184,7 +184,7 @@ export interface Connect {
<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = {}>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
mapDispatchToProps: TDispatchProps,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
): InferableComponentEnhancerWithProps<
TStateProps & ResolveThunks<TDispatchProps>,
TOwnProps
@@ -231,7 +231,7 @@ export interface Connect {
<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}>(
mapStateToProps: null | undefined,
mapDispatchToProps: TDispatchProps,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
mergeProps: null | undefined,
options: Options<{}, TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<
@@ -248,7 +248,7 @@ export interface Connect {
<TStateProps = {}, TDispatchProps = {}, TOwnProps = {}, State = {}>(
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
mapDispatchToProps: TDispatchProps,
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps>,
mergeProps: null | undefined,
options: Options<State, TStateProps, TOwnProps>
): InferableComponentEnhancerWithProps<
+29 -4
View File
@@ -1,7 +1,7 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Store, Dispatch, AnyAction, ActionCreator, createStore, bindActionCreators, ActionCreatorsMapObject, Reducer } from 'redux';
import { Connect, connect, Provider, DispatchProp, MapStateToProps, Options, ReactReduxContext, ReactReduxContextValue, Selector } from 'react-redux';
import { Connect, connect, Provider, DispatchProp, MapStateToProps, Options, ReactReduxContext, ReactReduxContextValue, Selector, MapDispatchToProps } from 'react-redux';
import objectAssign = require('object-assign');
//
@@ -82,9 +82,34 @@ function MapDispatch() {
class TestComponent extends React.Component<OwnProps & DispatchProps> { }
const mapDispatchToProps = () => ({
onClick: () => { }
});
const mapDispatchToProps = ({ onClick: () => {} });
const TestNull = connect(
null,
mapDispatchToProps,
)(TestComponent);
const verifyNull = <TestNull foo='bar' />;
const TestUndefined = connect(
undefined,
mapDispatchToProps,
)(TestComponent);
const verifyUndefined = <TestUndefined foo='bar' />;
}
function MapDispatchUnion() {
interface OwnProps { foo: string; }
interface DispatchProps { onClick: () => void; }
class TestComponent extends React.Component<OwnProps & DispatchProps> { }
// We deliberately cast the right-hand side to `any` because otherwise
// TypeScript would maintain the literal value, when we deliberately want to
// test the union type here (as per the annotation). See
// https://github.com/Microsoft/TypeScript/issues/30310#issuecomment-472218182.
const mapDispatchToProps: MapDispatchToProps<DispatchProps, OwnProps> = {} as any;
const TestNull = connect(
null,