[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
This commit is contained in:
Frank Tan
2017-08-15 10:13:01 -04:00
parent d4f42ab007
commit eaea12959d
2 changed files with 7 additions and 6 deletions

View File

@@ -5,6 +5,7 @@
// Thomas Hasner <https://github.com/thasner>,
// Kenzie Togami <https://github.com/kenzierocks>,
// Curits Layne <https://github.com/clayne11>
// Frank Tan <https://github.com/tansongyang>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
@@ -134,17 +135,17 @@ export declare function connect<TStateProps, TDispatchProps, TOwnProps, TMergedP
): InferableComponentEnhancerWithProps<TMergedProps, TOwnProps>;
interface MapStateToProps<TStateProps, TOwnProps> {
(state: any, ownProps?: TOwnProps): TStateProps;
(state: any, ownProps: TOwnProps): TStateProps;
}
interface MapStateToPropsFactory<TStateProps, TOwnProps> {
(initialState: any, ownProps?: TOwnProps): MapStateToProps<TStateProps, TOwnProps>;
(initialState: any, ownProps: TOwnProps): MapStateToProps<TStateProps, TOwnProps>;
}
type MapStateToPropsParam<TStateProps, TOwnProps> = MapStateToProps<TStateProps, TOwnProps> | MapStateToPropsFactory<TStateProps, TOwnProps>;
interface MapDispatchToPropsFunction<TDispatchProps, TOwnProps> {
(dispatch: Dispatch<any>, ownProps?: TOwnProps): TDispatchProps;
(dispatch: Dispatch<any>, ownProps: TOwnProps): TDispatchProps;
}
interface MapDispatchToPropsObject {
@@ -155,7 +156,7 @@ type MapDispatchToProps<TDispatchProps, TOwnProps> =
MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | MapDispatchToPropsObject;
interface MapDispatchToPropsFactory<TDispatchProps, TOwnProps> {
(dispatch: Dispatch<any>, ownProps?: TOwnProps): MapDispatchToProps<TDispatchProps, TOwnProps>;
(dispatch: Dispatch<any>, ownProps: TOwnProps): MapDispatchToProps<TDispatchProps, TOwnProps>;
}
type MapDispatchToPropsParam<TDispatchProps, TOwnProps> = MapDispatchToProps<TDispatchProps, TOwnProps> | MapDispatchToPropsFactory<TDispatchProps, TOwnProps>;

View File

@@ -63,8 +63,8 @@ connect<ICounterStateProps, ICounterDispatchProps, {}>(
)(Counter);
// with higher order functions using parameters
connect<ICounterStateProps, ICounterDispatchProps, {}>(
(initialState: CounterState, ownProps: {}) => mapStateToProps,
(dispatch: Dispatch<CounterState>, ownProps: {}) => mapDispatchToProps
(initialState: CounterState, ownProps) => mapStateToProps,
(dispatch: Dispatch<CounterState>, ownProps) => mapDispatchToProps
)(Counter);
// only first argument
connect<ICounterStateProps, {}, {}>(