@@ -12,11 +12,11 @@ import type {
12
12
} from './createAsyncThunk'
13
13
14
14
/** @public */
15
- export type ActionMatchingAnyOf < Matchers extends [ ... Matcher < any > [ ] ] > =
15
+ export type ActionMatchingAnyOf < Matchers extends Matcher < any > [ ] > =
16
16
ActionFromMatcher < Matchers [ number ] >
17
17
18
18
/** @public */
19
- export type ActionMatchingAllOf < Matchers extends [ ... Matcher < any > [ ] ] > =
19
+ export type ActionMatchingAllOf < Matchers extends Matcher < any > [ ] > =
20
20
UnionToIntersection < ActionMatchingAnyOf < Matchers > >
21
21
22
22
const matches = ( matcher : Matcher < any > , action : any ) => {
@@ -36,7 +36,7 @@ const matches = (matcher: Matcher<any>, action: any) => {
36
36
*
37
37
* @public
38
38
*/
39
- export function isAnyOf < Matchers extends [ ... Matcher < any > [ ] ] > (
39
+ export function isAnyOf < Matchers extends Matcher < any > [ ] > (
40
40
...matchers : Matchers
41
41
) {
42
42
return ( action : any ) : action is ActionMatchingAnyOf < Matchers > => {
@@ -53,7 +53,7 @@ export function isAnyOf<Matchers extends [...Matcher<any>[]]>(
53
53
*
54
54
* @public
55
55
*/
56
- export function isAllOf < Matchers extends [ ... Matcher < any > [ ] ] > (
56
+ export function isAllOf < Matchers extends Matcher < any > [ ] > (
57
57
...matchers : Matchers
58
58
) {
59
59
return ( action : any ) : action is ActionMatchingAllOf < Matchers > => {
@@ -136,18 +136,7 @@ export function isPending<
136
136
return isPending ( ) ( asyncThunks [ 0 ] )
137
137
}
138
138
139
- return (
140
- action : any ,
141
- ) : action is PendingActionFromAsyncThunk < AsyncThunks [ number ] > => {
142
- // note: this type will be correct because we have at least 1 asyncThunk
143
- const matchers : [ Matcher < any > , ...Matcher < any > [ ] ] = asyncThunks . map (
144
- ( asyncThunk ) => asyncThunk . pending ,
145
- ) as any
146
-
147
- const combinedMatcher = isAnyOf ( ...matchers )
148
-
149
- return combinedMatcher ( action )
150
- }
139
+ return isAnyOf ( ...asyncThunks . map ( ( asyncThunk ) => asyncThunk . pending ) )
151
140
}
152
141
153
142
export type UnknownAsyncThunkRejectedAction = ReturnType <
@@ -199,18 +188,7 @@ export function isRejected<
199
188
return isRejected ( ) ( asyncThunks [ 0 ] )
200
189
}
201
190
202
- return (
203
- action : any ,
204
- ) : action is RejectedActionFromAsyncThunk < AsyncThunks [ number ] > => {
205
- // note: this type will be correct because we have at least 1 asyncThunk
206
- const matchers : [ Matcher < any > , ...Matcher < any > [ ] ] = asyncThunks . map (
207
- ( asyncThunk ) => asyncThunk . rejected ,
208
- ) as any
209
-
210
- const combinedMatcher = isAnyOf ( ...matchers )
211
-
212
- return combinedMatcher ( action )
213
- }
191
+ return isAnyOf ( ...asyncThunks . map ( ( asyncThunk ) => asyncThunk . rejected ) )
214
192
}
215
193
216
194
export type UnknownAsyncThunkRejectedWithValueAction = ReturnType <
@@ -264,24 +242,14 @@ export function isRejectedWithValue<
264
242
}
265
243
266
244
if ( asyncThunks . length === 0 ) {
267
- return ( action : any ) => {
268
- const combinedMatcher = isAllOf ( isRejected ( ...asyncThunks ) , hasFlag )
269
-
270
- return combinedMatcher ( action )
271
- }
245
+ return isAllOf ( isRejected ( ...asyncThunks ) , hasFlag )
272
246
}
273
247
274
248
if ( ! isAsyncThunkArray ( asyncThunks ) ) {
275
249
return isRejectedWithValue ( ) ( asyncThunks [ 0 ] )
276
250
}
277
251
278
- return (
279
- action : any ,
280
- ) : action is RejectedActionFromAsyncThunk < AsyncThunks [ number ] > => {
281
- const combinedMatcher = isAllOf ( isRejected ( ...asyncThunks ) , hasFlag )
282
-
283
- return combinedMatcher ( action )
284
- }
252
+ return isAllOf ( isRejected ( ...asyncThunks ) , hasFlag )
285
253
}
286
254
287
255
export type UnknownAsyncThunkFulfilledAction = ReturnType <
@@ -333,18 +301,7 @@ export function isFulfilled<
333
301
return isFulfilled ( ) ( asyncThunks [ 0 ] )
334
302
}
335
303
336
- return (
337
- action : any ,
338
- ) : action is FulfilledActionFromAsyncThunk < AsyncThunks [ number ] > => {
339
- // note: this type will be correct because we have at least 1 asyncThunk
340
- const matchers : [ Matcher < any > , ...Matcher < any > [ ] ] = asyncThunks . map (
341
- ( asyncThunk ) => asyncThunk . fulfilled ,
342
- ) as any
343
-
344
- const combinedMatcher = isAnyOf ( ...matchers )
345
-
346
- return combinedMatcher ( action )
347
- }
304
+ return isAnyOf ( ...asyncThunks . map ( ( asyncThunk ) => asyncThunk . fulfilled ) )
348
305
}
349
306
350
307
export type UnknownAsyncThunkAction =
@@ -404,22 +361,5 @@ export function isAsyncThunkAction<
404
361
return isAsyncThunkAction ( ) ( asyncThunks [ 0 ] )
405
362
}
406
363
407
- return (
408
- action : any ,
409
- ) : action is ActionsFromAsyncThunk < AsyncThunks [ number ] > => {
410
- // note: this type will be correct because we have at least 1 asyncThunk
411
- const matchers : [ Matcher < any > , ...Matcher < any > [ ] ] = [ ] as any
412
-
413
- for ( const asyncThunk of asyncThunks ) {
414
- matchers . push (
415
- asyncThunk . pending ,
416
- asyncThunk . rejected ,
417
- asyncThunk . fulfilled ,
418
- )
419
- }
420
-
421
- const combinedMatcher = isAnyOf ( ...matchers )
422
-
423
- return combinedMatcher ( action )
424
- }
364
+ return isAnyOf ( ...asyncThunks . flatMap ( asyncThunk => [ asyncThunk . pending , asyncThunk . rejected , asyncThunk . fulfilled ] ) )
425
365
}
0 commit comments