From eaea12959d0655747ef880055fa56f3ba8002db2 Mon Sep 17 00:00:00 2001 From: Frank Tan Date: Tue, 15 Aug 2017 10:13:01 -0400 Subject: [PATCH] [react-redux] Do not mark ownProps as optional According to docs, "it's always legal to provide a callback that accepts fewer arguments": https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#optional-parameters-in-callbacks Morever, react-redux docs say that ownProps will have a value when it is specified as a callback argument: https://github.com/reactjs/react-redux/blob/master/docs/api.md#the-arity-of-mapstatetoprops-and-mapdispatchtoprops-determines-whether-they-receive-ownprops --- types/react-redux/index.d.ts | 9 +++++---- types/react-redux/react-redux-tests.tsx | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/types/react-redux/index.d.ts b/types/react-redux/index.d.ts index fc3c54bef1..c0a3692f2a 100644 --- a/types/react-redux/index.d.ts +++ b/types/react-redux/index.d.ts @@ -5,6 +5,7 @@ // Thomas Hasner , // Kenzie Togami , // Curits Layne +// Frank Tan // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 @@ -134,17 +135,17 @@ export declare function connect; interface MapStateToProps { - (state: any, ownProps?: TOwnProps): TStateProps; + (state: any, ownProps: TOwnProps): TStateProps; } interface MapStateToPropsFactory { - (initialState: any, ownProps?: TOwnProps): MapStateToProps; + (initialState: any, ownProps: TOwnProps): MapStateToProps; } type MapStateToPropsParam = MapStateToProps | MapStateToPropsFactory; interface MapDispatchToPropsFunction { - (dispatch: Dispatch, ownProps?: TOwnProps): TDispatchProps; + (dispatch: Dispatch, ownProps: TOwnProps): TDispatchProps; } interface MapDispatchToPropsObject { @@ -155,7 +156,7 @@ type MapDispatchToProps = MapDispatchToPropsFunction | MapDispatchToPropsObject; interface MapDispatchToPropsFactory { - (dispatch: Dispatch, ownProps?: TOwnProps): MapDispatchToProps; + (dispatch: Dispatch, ownProps: TOwnProps): MapDispatchToProps; } type MapDispatchToPropsParam = MapDispatchToProps | MapDispatchToPropsFactory; diff --git a/types/react-redux/react-redux-tests.tsx b/types/react-redux/react-redux-tests.tsx index 1bf9dae4f2..0ebcc3a820 100644 --- a/types/react-redux/react-redux-tests.tsx +++ b/types/react-redux/react-redux-tests.tsx @@ -63,8 +63,8 @@ connect( )(Counter); // with higher order functions using parameters connect( - (initialState: CounterState, ownProps: {}) => mapStateToProps, - (dispatch: Dispatch, ownProps: {}) => mapDispatchToProps + (initialState: CounterState, ownProps) => mapStateToProps, + (dispatch: Dispatch, ownProps) => mapDispatchToProps )(Counter); // only first argument connect(