@@ -3,18 +3,23 @@ import { Dispatch } from 'redux'
33import { FixTypeLater } from '../types'
44import verifyPlainObject from '../utils/verifyPlainObject'
55
6- export type MapToProps = {
7- ( stateOrDispatch : FixTypeLater , ownProps ?: unknown ) : FixTypeLater
6+ type AnyState = { [ key : string ] : any }
7+ type StateOrDispatch < S = AnyState > = S | Dispatch
8+
9+ type AnyProps = { [ key : string ] : any }
10+
11+ export type MapToProps < P = AnyProps > = {
12+ ( stateOrDispatch : StateOrDispatch , ownProps ?: P ) : FixTypeLater
813 dependsOnOwnProps : boolean
914}
1015
1116export function wrapMapToPropsConstant (
1217 // * Note:
13- // It seems that the dispatch identifier here
14- // could be dispatch in some cases (ex: whenMapDispatchToPropsIsMissing)
15- // and state in some others (ex: whenMapStateToPropsIsMissing)
18+ // It seems that the dispatch argument
19+ // could be a dispatch function in some cases (ex: whenMapDispatchToPropsIsMissing)
20+ // and a state object in some others (ex: whenMapStateToPropsIsMissing)
1621 //
17- getConstant : ( dispatch : Dispatch ) => FixTypeLater
22+ getConstant : ( dispatch : Dispatch ) => { dispatch : Dispatch }
1823) {
1924 return function initConstantSelector ( dispatch : Dispatch ) {
2025 const constant = getConstant ( dispatch )
@@ -52,26 +57,29 @@ export function getDependsOnOwnProps(mapToProps: MapToProps) {
5257// * On first call, verifies the first result is a plain object, in order to warn
5358// the developer that their mapToProps function is not returning a valid result.
5459//
55- export function wrapMapToPropsFunc ( mapToProps : MapToProps , methodName : string ) {
60+ export function wrapMapToPropsFunc < P = AnyProps > (
61+ mapToProps : MapToProps ,
62+ methodName : string
63+ ) {
5664 return function initProxySelector (
5765 dispatch : Dispatch ,
5866 { displayName } : { displayName : string }
5967 ) {
6068 const proxy = function mapToPropsProxy (
6169 stateOrDispatch : FixTypeLater ,
62- ownProps : unknown
70+ ownProps ?: P
6371 ) : FixTypeLater {
6472 return proxy . dependsOnOwnProps
6573 ? proxy . mapToProps ( stateOrDispatch , ownProps )
66- : proxy . mapToProps ( stateOrDispatch , null )
74+ : proxy . mapToProps ( stateOrDispatch , undefined )
6775 }
6876
6977 // allow detectFactoryAndVerify to get ownProps
7078 proxy . dependsOnOwnProps = true
7179
7280 proxy . mapToProps = function detectFactoryAndVerify (
7381 stateOrDispatch : FixTypeLater ,
74- ownProps : unknown
82+ ownProps ?: P
7583 ) {
7684 proxy . mapToProps = mapToProps
7785 proxy . dependsOnOwnProps = getDependsOnOwnProps ( mapToProps )
0 commit comments