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