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