@@ -3,7 +3,7 @@ import verifySubselectors from './verifySubselectors'
3
3
import type { EqualityFn } from '../types'
4
4
5
5
export type SelectorFactory < S , TProps , TOwnProps , TFactoryOptions > = (
6
- dispatch : Dispatch < Action > ,
6
+ dispatch : Dispatch < Action < unknown > > ,
7
7
factoryOptions : TFactoryOptions
8
8
) => Selector < S , TProps , TOwnProps >
9
9
@@ -13,24 +13,24 @@ export type Selector<S, TProps, TOwnProps = null> = TOwnProps extends
13
13
? ( state : S ) => TProps
14
14
: ( state : S , ownProps : TOwnProps ) => TProps
15
15
16
- export type MapStateToProps < TStateProps , TOwnProps , State = unknown > = (
16
+ export type MapStateToProps < TStateProps , TOwnProps , State > = (
17
17
state : State ,
18
18
ownProps : TOwnProps
19
19
) => TStateProps
20
20
21
- export type MapStateToPropsFactory < TStateProps , TOwnProps , State = unknown > = (
21
+ export type MapStateToPropsFactory < TStateProps , TOwnProps , State > = (
22
22
initialState : State ,
23
23
ownProps : TOwnProps
24
24
) => MapStateToProps < TStateProps , TOwnProps , State >
25
25
26
- export type MapStateToPropsParam < TStateProps , TOwnProps , State = unknown > =
26
+ export type MapStateToPropsParam < TStateProps , TOwnProps , State > =
27
27
| MapStateToPropsFactory < TStateProps , TOwnProps , State >
28
28
| MapStateToProps < TStateProps , TOwnProps , State >
29
29
| null
30
30
| undefined
31
31
32
32
export type MapDispatchToPropsFunction < TDispatchProps , TOwnProps > = (
33
- dispatch : Dispatch < Action > ,
33
+ dispatch : Dispatch < Action < unknown > > ,
34
34
ownProps : TOwnProps
35
35
) => TDispatchProps
36
36
@@ -39,7 +39,7 @@ export type MapDispatchToProps<TDispatchProps, TOwnProps> =
39
39
| TDispatchProps
40
40
41
41
export type MapDispatchToPropsFactory < TDispatchProps , TOwnProps > = (
42
- dispatch : Dispatch < Action > ,
42
+ dispatch : Dispatch < Action < unknown > > ,
43
43
ownProps : TOwnProps
44
44
) => MapDispatchToPropsFunction < TDispatchProps , TOwnProps >
45
45
@@ -57,10 +57,10 @@ export type MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps> = (
57
57
ownProps : TOwnProps
58
58
) => TMergedProps
59
59
60
- interface PureSelectorFactoryComparisonOptions < TOwnProps , State = unknown > {
60
+ interface PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State > {
61
61
areStatesEqual : EqualityFn < State >
62
62
areOwnPropsEqual : EqualityFn < TOwnProps >
63
- areStatePropsEqual : EqualityFn < unknown >
63
+ areStatePropsEqual : EqualityFn < TStateProps >
64
64
displayName : string
65
65
}
66
66
@@ -69,21 +69,17 @@ export function pureFinalPropsSelectorFactory<
69
69
TOwnProps ,
70
70
TDispatchProps ,
71
71
TMergedProps ,
72
- State = unknown
72
+ State
73
73
> (
74
- mapStateToProps : MapStateToPropsParam < TStateProps , TOwnProps , State > & {
75
- dependsOnOwnProps : boolean
76
- } ,
77
- mapDispatchToProps : MapDispatchToPropsParam < TDispatchProps , TOwnProps > & {
78
- dependsOnOwnProps : boolean
79
- } ,
74
+ mapStateToProps : WrappedMapStateToProps < TStateProps , TOwnProps , State > ,
75
+ mapDispatchToProps : WrappedMapDispatchToProps < TDispatchProps , TOwnProps > ,
80
76
mergeProps : MergeProps < TStateProps , TDispatchProps , TOwnProps , TMergedProps > ,
81
- dispatch : Dispatch ,
77
+ dispatch : Dispatch < Action < unknown > > ,
82
78
{
83
79
areStatesEqual,
84
80
areOwnPropsEqual,
85
81
areStatePropsEqual,
86
- } : PureSelectorFactoryComparisonOptions < TOwnProps , State >
82
+ } : PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State >
87
83
) {
88
84
let hasRunAtLeastOnce = false
89
85
let state : State
@@ -95,34 +91,28 @@ export function pureFinalPropsSelectorFactory<
95
91
function handleFirstCall ( firstState : State , firstOwnProps : TOwnProps ) {
96
92
state = firstState
97
93
ownProps = firstOwnProps
98
- // @ts -ignore
99
- stateProps = mapStateToProps ! ( state , ownProps )
100
- // @ts -ignore
101
- dispatchProps = mapDispatchToProps ! ( dispatch , ownProps )
94
+ stateProps = mapStateToProps ( state , ownProps )
95
+ dispatchProps = mapDispatchToProps ( dispatch , ownProps )
102
96
mergedProps = mergeProps ( stateProps , dispatchProps , ownProps )
103
97
hasRunAtLeastOnce = true
104
98
return mergedProps
105
99
}
106
100
107
101
function handleNewPropsAndNewState ( ) {
108
- // @ts -ignore
109
- stateProps = mapStateToProps ! ( state , ownProps )
102
+ stateProps = mapStateToProps ( state , ownProps )
110
103
111
- if ( mapDispatchToProps ! . dependsOnOwnProps )
112
- // @ts -ignore
104
+ if ( mapDispatchToProps . dependsOnOwnProps )
113
105
dispatchProps = mapDispatchToProps ( dispatch , ownProps )
114
106
115
107
mergedProps = mergeProps ( stateProps , dispatchProps , ownProps )
116
108
return mergedProps
117
109
}
118
110
119
111
function handleNewProps ( ) {
120
- if ( mapStateToProps ! . dependsOnOwnProps )
121
- // @ts -ignore
122
- stateProps = mapStateToProps ! ( state , ownProps )
112
+ if ( mapStateToProps . dependsOnOwnProps )
113
+ stateProps = mapStateToProps ( state , ownProps )
123
114
124
115
if ( mapDispatchToProps . dependsOnOwnProps )
125
- // @ts -ignore
126
116
dispatchProps = mapDispatchToProps ( dispatch , ownProps )
127
117
128
118
mergedProps = mergeProps ( stateProps , dispatchProps , ownProps )
@@ -132,7 +122,6 @@ export function pureFinalPropsSelectorFactory<
132
122
function handleNewState ( ) {
133
123
const nextStateProps = mapStateToProps ( state , ownProps )
134
124
const statePropsChanged = ! areStatePropsEqual ( nextStateProps , stateProps )
135
- // @ts -ignore
136
125
stateProps = nextStateProps
137
126
138
127
if ( statePropsChanged )
@@ -163,24 +152,34 @@ export function pureFinalPropsSelectorFactory<
163
152
}
164
153
}
165
154
155
+ interface WrappedMapStateToProps < TStateProps , TOwnProps , State > {
156
+ ( state : State , ownProps : TOwnProps ) : TStateProps
157
+ readonly dependsOnOwnProps : boolean
158
+ }
159
+
160
+ interface WrappedMapDispatchToProps < TDispatchProps , TOwnProps > {
161
+ ( dispatch : Dispatch < Action < unknown > > , ownProps : TOwnProps ) : TDispatchProps
162
+ readonly dependsOnOwnProps : boolean
163
+ }
164
+
166
165
export interface SelectorFactoryOptions <
167
166
TStateProps ,
168
167
TOwnProps ,
169
168
TDispatchProps ,
170
169
TMergedProps ,
171
- State = unknown
172
- > extends PureSelectorFactoryComparisonOptions < TOwnProps , State > {
170
+ State
171
+ > extends PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State > {
173
172
initMapStateToProps : (
174
173
dispatch : Dispatch ,
175
- options : PureSelectorFactoryComparisonOptions < TOwnProps , State >
176
- ) => MapStateToPropsParam < TStateProps , TOwnProps , State >
174
+ options : PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State >
175
+ ) => WrappedMapStateToProps < TStateProps , TOwnProps , State >
177
176
initMapDispatchToProps : (
178
177
dispatch : Dispatch ,
179
- options : PureSelectorFactoryComparisonOptions < TOwnProps , State >
180
- ) => MapDispatchToPropsParam < TDispatchProps , TOwnProps >
178
+ options : PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State >
179
+ ) => WrappedMapDispatchToProps < TDispatchProps , TOwnProps >
181
180
initMergeProps : (
182
181
dispatch : Dispatch ,
183
- options : PureSelectorFactoryComparisonOptions < TOwnProps , State >
182
+ options : PureSelectorFactoryComparisonOptions < TStateProps , TOwnProps , State >
184
183
) => MergeProps < TStateProps , TDispatchProps , TOwnProps , TMergedProps >
185
184
}
186
185
@@ -195,9 +194,9 @@ export default function finalPropsSelectorFactory<
195
194
TOwnProps ,
196
195
TDispatchProps ,
197
196
TMergedProps ,
198
- State = unknown
197
+ State
199
198
> (
200
- dispatch : Dispatch < Action > ,
199
+ dispatch : Dispatch < Action < unknown > > ,
201
200
{
202
201
initMapStateToProps,
203
202
initMapDispatchToProps,
@@ -225,6 +224,5 @@ export default function finalPropsSelectorFactory<
225
224
TDispatchProps ,
226
225
TMergedProps ,
227
226
State
228
- // @ts -ignore
229
- > ( mapStateToProps ! , mapDispatchToProps , mergeProps , dispatch , options )
227
+ > ( mapStateToProps , mapDispatchToProps , mergeProps , dispatch , options )
230
228
}
0 commit comments