mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-05 20:02:05 +08:00
Merge pull request #19143 from coreh/fix/react-redux-dispatch-to-props-object
react-redux: fix dispatchToProps being passed as object
This commit is contained in:
10
types/react-redux/index.d.ts
vendored
10
types/react-redux/index.d.ts
vendored
@@ -148,12 +148,8 @@ interface MapDispatchToPropsFunction<TDispatchProps, TOwnProps> {
|
||||
(dispatch: Dispatch<any>, ownProps: TOwnProps): TDispatchProps;
|
||||
}
|
||||
|
||||
interface MapDispatchToPropsObject {
|
||||
[name: string]: ActionCreator<any>;
|
||||
}
|
||||
|
||||
type MapDispatchToProps<TDispatchProps, TOwnProps> =
|
||||
MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | MapDispatchToPropsObject;
|
||||
MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | TDispatchProps;
|
||||
|
||||
interface MapDispatchToPropsFactory<TDispatchProps, TOwnProps> {
|
||||
(dispatch: Dispatch<any>, ownProps: TOwnProps): MapDispatchToProps<TDispatchProps, TOwnProps>;
|
||||
@@ -180,13 +176,13 @@ interface Options<TStateProps = {}, TOwnProps = {}, TMergedProps = {}> extends C
|
||||
* @default strictEqual
|
||||
*/
|
||||
areStatesEqual?: (nextState: any, prevState: any) => boolean;
|
||||
|
||||
|
||||
/**
|
||||
* When pure, compares incoming props to its previous value.
|
||||
* @default shallowEqual
|
||||
*/
|
||||
areOwnPropsEqual?: (nextOwnProps: TOwnProps, prevOwnProps: TOwnProps) => boolean;
|
||||
|
||||
|
||||
/**
|
||||
* When pure, compares the result of mapStateToProps to its previous value.
|
||||
* @default shallowEqual
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Component, ReactElement } from 'react';
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import { Store, Dispatch, bindActionCreators } from 'redux';
|
||||
import { Store, Dispatch, ActionCreator, bindActionCreators } from 'redux';
|
||||
import { connect, Provider, DispatchProp, MapStateToProps } from 'react-redux';
|
||||
import objectAssign = require('object-assign');
|
||||
|
||||
@@ -549,3 +549,23 @@ namespace TestControlledComponentWithoutDispatchProp {
|
||||
const MyControlledComponent = connect(mapStateToProps)(MyComponent);
|
||||
const MyControlledFuncComponent = connect(mapStateToProps)(MyFuncComponent);
|
||||
}
|
||||
|
||||
namespace TestDispatchToPropsAsObject {
|
||||
const onClick: ActionCreator<{}> = null;
|
||||
const mapStateToProps = (state: any) => {
|
||||
return {
|
||||
title: state.app.title as string,
|
||||
};
|
||||
};
|
||||
const dispatchToProps = {
|
||||
onClick,
|
||||
};
|
||||
|
||||
type Props = { title: string; } & typeof dispatchToProps;
|
||||
const HeaderComponent: React.StatelessComponent<Props> = (props) => {
|
||||
return <h1>{props.title}</h1>;
|
||||
}
|
||||
|
||||
const Header = connect(mapStateToProps, dispatchToProps)(HeaderComponent);
|
||||
<Header />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user