@@ -16,7 +16,15 @@ import type {
16
16
import { createReducer , makeGetInitialState } from './createReducer'
17
17
import type { ActionReducerMapBuilder , TypedActionCreator } from './mapBuilders'
18
18
import { executeReducerBuilderCallback } from './mapBuilders'
19
- import type { CastAny , Id , TypeGuard , UnionToIntersection } from './tsHelpers'
19
+ import type {
20
+ CastAny ,
21
+ Id ,
22
+ Increment ,
23
+ IsAny ,
24
+ OverloadedReturnType ,
25
+ TypeGuard ,
26
+ UnionToIntersection ,
27
+ } from './tsHelpers'
20
28
import type { InjectConfig } from './combineSlices'
21
29
import { emplace } from './utils'
22
30
@@ -265,54 +273,48 @@ export interface ReducerDetails {
265
273
type : string
266
274
}
267
275
268
- type RecursiveExtractDefinition <
269
- Definitions ,
276
+ type DefinitionFromValue <
277
+ T extends object ,
270
278
Type extends RegisteredReducerType ,
271
- > = CastAny <
272
- | Extract < Definitions , ReducerDefinition < Type > >
273
- | ( Definitions extends object
274
- ? {
275
- [ K in keyof Definitions ] -?: RecursiveExtractDefinition <
276
- Definitions [ K ] ,
277
- Type
278
- >
279
- } [ keyof Definitions ]
280
- : never ) ,
281
- never
282
- >
279
+ RecursionDepth extends number = 0 ,
280
+ > = RecursionDepth extends 5
281
+ ? never
282
+ : IsAny <
283
+ T ,
284
+ never ,
285
+ | Extract < T , ReducerDefinition < Type > >
286
+ | {
287
+ [ K in keyof T ] -?: T [ K ] extends object
288
+ ? DefinitionFromValue < T [ K ] , Type , Increment < RecursionDepth > >
289
+ : never
290
+ } [ keyof T ]
291
+ | ( T extends ( ...args : any [ ] ) => object
292
+ ? DefinitionFromValue <
293
+ OverloadedReturnType < T > ,
294
+ Type ,
295
+ Increment < RecursionDepth >
296
+ >
297
+ : never )
298
+ >
283
299
284
300
type ReducerDefinitionsForType < Type extends RegisteredReducerType > = {
285
- [ CreatorType in RegisteredReducerType ] :
286
- | RecursiveExtractDefinition <
287
- ReturnType <
288
- SliceReducerCreators < any , any , any , any > [ CreatorType ] [ 'create' ]
289
- > ,
290
- Type
291
- >
292
- | {
293
- [ K in keyof SliceReducerCreators <
294
- any ,
295
- any ,
296
- any ,
297
- any
298
- > [ CreatorType ] [ 'create' ] ] : SliceReducerCreators <
299
- any ,
300
- any ,
301
- any ,
302
- any
303
- > [ CreatorType ] [ 'create' ] [ K ] extends (
304
- ...args : any [ ]
305
- ) => infer Definitions
306
- ? RecursiveExtractDefinition < Definitions , Type >
307
- : never
308
- } [ keyof SliceReducerCreators < any , any , any , any > [ CreatorType ] [ 'create' ] ]
301
+ [ CreatorType in RegisteredReducerType ] : DefinitionFromValue <
302
+ SliceReducerCreators < any , any , any , any > [ CreatorType ] [ 'create' ] ,
303
+ Type
304
+ >
309
305
} [ RegisteredReducerType ]
310
306
311
307
export type ReducerCreator < Type extends RegisteredReducerType > = {
312
308
type : Type
313
309
create : SliceReducerCreators < any , any , any , any > [ Type ] [ 'create' ]
314
310
} & ( ReducerDefinitionsForType < Type > extends never
315
- ? { }
311
+ ? {
312
+ handle ?< State > (
313
+ details : ReducerDetails ,
314
+ definition : unknown ,
315
+ context : ReducerHandlingContext < State > ,
316
+ ) : void
317
+ }
316
318
: {
317
319
handle < State > (
318
320
details : ReducerDetails ,
0 commit comments