@@ -3,34 +3,32 @@ import verifySubselectors from './verifySubselectors'
33import type { EqualityFn } from '../types'
44
55export type SelectorFactory < S , TProps , TOwnProps , TFactoryOptions > = (
6- dispatch : Dispatch < Action > ,
6+ dispatch : Dispatch < Action < unknown > > ,
77 factoryOptions : TFactoryOptions
88) => Selector < S , TProps , TOwnProps >
99
10- export type Selector < S , TProps , TOwnProps = null > = TOwnProps extends
11- | null
12- | undefined
10+ export type Selector < S , TProps , TOwnProps > = TOwnProps extends null | undefined
1311 ? ( state : S ) => TProps
1412 : ( state : S , ownProps : TOwnProps ) => TProps
1513
16- export type MapStateToProps < TStateProps , TOwnProps , State = unknown > = (
14+ export type MapStateToProps < TStateProps , TOwnProps , State > = (
1715 state : State ,
1816 ownProps : TOwnProps
1917) => TStateProps
2018
21- export type MapStateToPropsFactory < TStateProps , TOwnProps , State = unknown > = (
19+ export type MapStateToPropsFactory < TStateProps , TOwnProps , State > = (
2220 initialState : State ,
2321 ownProps : TOwnProps
2422) => MapStateToProps < TStateProps , TOwnProps , State >
2523
26- export type MapStateToPropsParam < TStateProps , TOwnProps , State = unknown > =
24+ export type MapStateToPropsParam < TStateProps , TOwnProps , State > =
2725 | MapStateToPropsFactory < TStateProps , TOwnProps , State >
2826 | MapStateToProps < TStateProps , TOwnProps , State >
2927 | null
3028 | undefined
3129
3230export type MapDispatchToPropsFunction < TDispatchProps , TOwnProps > = (
33- dispatch : Dispatch < Action > ,
31+ dispatch : Dispatch < Action < unknown > > ,
3432 ownProps : TOwnProps
3533) => TDispatchProps
3634
@@ -39,7 +37,7 @@ export type MapDispatchToProps<TDispatchProps, TOwnProps> =
3937 | TDispatchProps
4038
4139export type MapDispatchToPropsFactory < TDispatchProps , TOwnProps > = (
42- dispatch : Dispatch < Action > ,
40+ dispatch : Dispatch < Action < unknown > > ,
4341 ownProps : TOwnProps
4442) => MapDispatchToPropsFunction < TDispatchProps , TOwnProps >
4543
@@ -57,10 +55,10 @@ export type MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps> = (
5755 ownProps : TOwnProps
5856) => TMergedProps
5957
60- interface PureSelectorFactoryComparisonOptions < TOwnProps , State = unknown > {
58+ interface PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State > {
6159 areStatesEqual : EqualityFn < State >
6260 areOwnPropsEqual : EqualityFn < TOwnProps >
63- areStatePropsEqual : EqualityFn < unknown >
61+ areStatePropsEqual : EqualityFn < TStateProps >
6462 displayName : string
6563}
6664
@@ -69,21 +67,17 @@ export function pureFinalPropsSelectorFactory<
6967 TOwnProps ,
7068 TDispatchProps ,
7169 TMergedProps ,
72- State = unknown
70+ State
7371> (
74- mapStateToProps : MapStateToPropsParam < TStateProps , TOwnProps , State > & {
75- dependsOnOwnProps : boolean
76- } ,
77- mapDispatchToProps : MapDispatchToPropsParam < TDispatchProps , TOwnProps > & {
78- dependsOnOwnProps : boolean
79- } ,
72+ mapStateToProps : WrappedMapStateToProps < TStateProps , TOwnProps , State > ,
73+ mapDispatchToProps : WrappedMapDispatchToProps < TDispatchProps , TOwnProps > ,
8074 mergeProps : MergeProps < TStateProps , TDispatchProps , TOwnProps , TMergedProps > ,
81- dispatch : Dispatch ,
75+ dispatch : Dispatch < Action < unknown > > ,
8276 {
8377 areStatesEqual,
8478 areOwnPropsEqual,
8579 areStatePropsEqual,
86- } : PureSelectorFactoryComparisonOptions < TOwnProps , State >
80+ } : PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State >
8781) {
8882 let hasRunAtLeastOnce = false
8983 let state : State
@@ -95,34 +89,28 @@ export function pureFinalPropsSelectorFactory<
9589 function handleFirstCall ( firstState : State , firstOwnProps : TOwnProps ) {
9690 state = firstState
9791 ownProps = firstOwnProps
98- // @ts -ignore
99- stateProps = mapStateToProps ! ( state , ownProps )
100- // @ts -ignore
101- dispatchProps = mapDispatchToProps ! ( dispatch , ownProps )
92+ stateProps = mapStateToProps ( state , ownProps )
93+ dispatchProps = mapDispatchToProps ( dispatch , ownProps )
10294 mergedProps = mergeProps ( stateProps , dispatchProps , ownProps )
10395 hasRunAtLeastOnce = true
10496 return mergedProps
10597 }
10698
10799 function handleNewPropsAndNewState ( ) {
108- // @ts -ignore
109- stateProps = mapStateToProps ! ( state , ownProps )
100+ stateProps = mapStateToProps ( state , ownProps )
110101
111- if ( mapDispatchToProps ! . dependsOnOwnProps )
112- // @ts -ignore
102+ if ( mapDispatchToProps . dependsOnOwnProps )
113103 dispatchProps = mapDispatchToProps ( dispatch , ownProps )
114104
115105 mergedProps = mergeProps ( stateProps , dispatchProps , ownProps )
116106 return mergedProps
117107 }
118108
119109 function handleNewProps ( ) {
120- if ( mapStateToProps ! . dependsOnOwnProps )
121- // @ts -ignore
122- stateProps = mapStateToProps ! ( state , ownProps )
110+ if ( mapStateToProps . dependsOnOwnProps )
111+ stateProps = mapStateToProps ( state , ownProps )
123112
124113 if ( mapDispatchToProps . dependsOnOwnProps )
125- // @ts -ignore
126114 dispatchProps = mapDispatchToProps ( dispatch , ownProps )
127115
128116 mergedProps = mergeProps ( stateProps , dispatchProps , ownProps )
@@ -132,7 +120,6 @@ export function pureFinalPropsSelectorFactory<
132120 function handleNewState ( ) {
133121 const nextStateProps = mapStateToProps ( state , ownProps )
134122 const statePropsChanged = ! areStatePropsEqual ( nextStateProps , stateProps )
135- // @ts -ignore
136123 stateProps = nextStateProps
137124
138125 if ( statePropsChanged )
@@ -163,24 +150,34 @@ export function pureFinalPropsSelectorFactory<
163150 }
164151}
165152
153+ interface WrappedMapStateToProps < TStateProps , TOwnProps , State > {
154+ ( state : State , ownProps : TOwnProps ) : TStateProps
155+ readonly dependsOnOwnProps : boolean
156+ }
157+
158+ interface WrappedMapDispatchToProps < TDispatchProps , TOwnProps > {
159+ ( dispatch : Dispatch < Action < unknown > > , ownProps : TOwnProps ) : TDispatchProps
160+ readonly dependsOnOwnProps : boolean
161+ }
162+
166163export interface SelectorFactoryOptions <
167164 TStateProps ,
168165 TOwnProps ,
169166 TDispatchProps ,
170167 TMergedProps ,
171- State = unknown
172- > extends PureSelectorFactoryComparisonOptions < TOwnProps , State > {
168+ State
169+ > extends PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State > {
173170 initMapStateToProps : (
174171 dispatch : Dispatch ,
175- options : PureSelectorFactoryComparisonOptions < TOwnProps , State >
176- ) => MapStateToPropsParam < TStateProps , TOwnProps , State >
172+ options : PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State >
173+ ) => WrappedMapStateToProps < TStateProps , TOwnProps , State >
177174 initMapDispatchToProps : (
178175 dispatch : Dispatch ,
179- options : PureSelectorFactoryComparisonOptions < TOwnProps , State >
180- ) => MapDispatchToPropsParam < TDispatchProps , TOwnProps >
176+ options : PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State >
177+ ) => WrappedMapDispatchToProps < TDispatchProps , TOwnProps >
181178 initMergeProps : (
182179 dispatch : Dispatch ,
183- options : PureSelectorFactoryComparisonOptions < TOwnProps , State >
180+ options : PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State >
184181 ) => MergeProps < TStateProps , TDispatchProps , TOwnProps , TMergedProps >
185182}
186183
@@ -195,9 +192,9 @@ export default function finalPropsSelectorFactory<
195192 TOwnProps ,
196193 TDispatchProps ,
197194 TMergedProps ,
198- State = unknown
195+ State
199196> (
200- dispatch : Dispatch < Action > ,
197+ dispatch : Dispatch < Action < unknown > > ,
201198 {
202199 initMapStateToProps,
203200 initMapDispatchToProps,
@@ -225,6 +222,5 @@ export default function finalPropsSelectorFactory<
225222 TDispatchProps ,
226223 TMergedProps ,
227224 State
228- // @ts -ignore
229- > ( mapStateToProps ! , mapDispatchToProps , mergeProps , dispatch , options )
225+ > ( mapStateToProps , mapDispatchToProps , mergeProps , dispatch , options )
230226}
0 commit comments