Skip to content

Commit 17cad3c

Browse files
committed
Merge branch 'create-slice-creators' into entity-methods-creator
2 parents 2fb97e5 + f86a6d5 commit 17cad3c

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

packages/toolkit/src/createSlice.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,15 @@ type CreatorCallback<
507507
) => Record<string, ReducerDefinition>
508508

509509
type GetCaseReducers<
510-
CR extends SliceCaseReducers<any> | CreatorCallback<any, any, any, any>,
511-
> = CR extends CreatorCallback<any, any, any, any> ? ReturnType<CR> : CR
510+
State,
511+
Name extends string,
512+
ReducerPath extends string,
513+
CreatorMap extends Record<string, RegisteredReducerType>,
514+
CR extends SliceCaseReducers<State> | CreatorCallback<State, any, any, any>,
515+
> =
516+
CR extends CreatorCallback<State, Name, ReducerPath, CreatorMap>
517+
? ReturnType<CR>
518+
: CR
512519

513520
/**
514521
* Options for `createSlice()`.
@@ -907,7 +914,13 @@ export function buildCreateSlice<
907914
Selectors,
908915
CreatorMap
909916
>,
910-
): Slice<State, GetCaseReducers<CaseReducers>, Name, ReducerPath, Selectors> {
917+
): Slice<
918+
State,
919+
GetCaseReducers<State, Name, ReducerPath, CreatorMap, CaseReducers>,
920+
Name,
921+
ReducerPath,
922+
Selectors
923+
> {
911924
const { name, reducerPath = name as unknown as ReducerPath } = options
912925
if (!name) {
913926
throw new Error('`name` is a required option for createSlice')
@@ -1104,7 +1117,7 @@ export function buildCreateSlice<
11041117
): Pick<
11051118
Slice<
11061119
State,
1107-
GetCaseReducers<CaseReducers>,
1120+
GetCaseReducers<State, Name, ReducerPath, CreatorMap, CaseReducers>,
11081121
Name,
11091122
CurrentReducerPath,
11101123
Selectors
@@ -1160,7 +1173,7 @@ export function buildCreateSlice<
11601173

11611174
const slice: Slice<
11621175
State,
1163-
GetCaseReducers<CaseReducers>,
1176+
GetCaseReducers<State, Name, ReducerPath, CreatorMap, CaseReducers>,
11641177
Name,
11651178
ReducerPath,
11661179
Selectors

0 commit comments

Comments
 (0)