@@ -52,7 +52,7 @@ export interface Slice<
52
52
* Action creators for the types of actions that are handled by the slice
53
53
* reducer.
54
54
*/
55
- actions : CaseReducerActions < CaseReducers >
55
+ actions : CaseReducerActions < CaseReducers , Name >
56
56
57
57
/**
58
58
* The individual case reducer functions that were passed in the `reducers` parameter.
@@ -165,38 +165,54 @@ export type SliceCaseReducers<State> = {
165
165
| CaseReducerWithPrepare < State , PayloadAction < any , string , any , any > >
166
166
}
167
167
168
+ type SliceActionType <
169
+ SliceName extends string ,
170
+ ActionName extends keyof any
171
+ > = ActionName extends string | number ? `${SliceName } /${ActionName } ` : string
172
+
168
173
/**
169
174
* Derives the slice's `actions` property from the `reducers` options
170
175
*
171
176
* @public
172
177
*/
173
- export type CaseReducerActions < CaseReducers extends SliceCaseReducers < any > > = {
178
+ export type CaseReducerActions <
179
+ CaseReducers extends SliceCaseReducers < any > ,
180
+ SliceName extends string
181
+ > = {
174
182
[ Type in keyof CaseReducers ] : CaseReducers [ Type ] extends { prepare : any }
175
- ? ActionCreatorForCaseReducerWithPrepare < CaseReducers [ Type ] >
176
- : ActionCreatorForCaseReducer < CaseReducers [ Type ] >
183
+ ? ActionCreatorForCaseReducerWithPrepare <
184
+ CaseReducers [ Type ] ,
185
+ SliceActionType < SliceName , Type >
186
+ >
187
+ : ActionCreatorForCaseReducer <
188
+ CaseReducers [ Type ] ,
189
+ SliceActionType < SliceName , Type >
190
+ >
177
191
}
178
192
179
193
/**
180
194
* Get a `PayloadActionCreator` type for a passed `CaseReducerWithPrepare`
181
195
*
182
196
* @internal
183
197
*/
184
- type ActionCreatorForCaseReducerWithPrepare < CR extends { prepare : any } > =
185
- _ActionCreatorWithPreparedPayload < CR [ 'prepare' ] , string >
198
+ type ActionCreatorForCaseReducerWithPrepare <
199
+ CR extends { prepare : any } ,
200
+ Type extends string
201
+ > = _ActionCreatorWithPreparedPayload < CR [ 'prepare' ] , Type >
186
202
187
203
/**
188
204
* Get a `PayloadActionCreator` type for a passed `CaseReducer`
189
205
*
190
206
* @internal
191
207
*/
192
- type ActionCreatorForCaseReducer < CR > = CR extends (
208
+ type ActionCreatorForCaseReducer < CR , Type extends string > = CR extends (
193
209
state : any ,
194
210
action : infer Action
195
211
) => any
196
212
? Action extends { payload : infer P }
197
- ? PayloadActionCreator < P >
198
- : ActionCreatorWithoutPayload
199
- : ActionCreatorWithoutPayload
213
+ ? PayloadActionCreator < P , Type >
214
+ : ActionCreatorWithoutPayload < Type >
215
+ : ActionCreatorWithoutPayload < Type >
200
216
201
217
/**
202
218
* Extracts the CaseReducers out of a `reducers` object, even if they are
0 commit comments