Skip to content

Commit 4decf83

Browse files
committed
Merge branch 'entity-methods-creator' into per-slice-creator
2 parents 0ccf470 + ed623ac commit 4decf83

File tree

3 files changed

+45
-60
lines changed

3 files changed

+45
-60
lines changed

packages/toolkit/src/asyncThunkCreator.ts

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,6 @@ import type {
1616
import { ReducerType } from './createSlice'
1717
import type { Id } from './tsHelpers'
1818

19-
declare module './createSlice' {
20-
export interface SliceReducerCreators<
21-
State,
22-
CaseReducers extends CreatorCaseReducers<State>,
23-
Name extends string,
24-
ReducerPath extends string,
25-
> {
26-
[ReducerType.asyncThunk]: ReducerCreatorEntry<
27-
AsyncThunkCreator<State>,
28-
{
29-
actions: {
30-
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
31-
State,
32-
infer ThunkArg,
33-
infer Returned,
34-
infer ThunkApiConfig
35-
>
36-
? AsyncThunk<Returned, ThunkArg, ThunkApiConfig>
37-
: never
38-
}
39-
caseReducers: {
40-
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
41-
State,
42-
any,
43-
any,
44-
any
45-
>
46-
? Id<
47-
Pick<
48-
Required<CaseReducers[ReducerName]>,
49-
'fulfilled' | 'rejected' | 'pending' | 'settled'
50-
>
51-
>
52-
: never
53-
}
54-
}
55-
>
56-
}
57-
}
58-
5919
export type AsyncThunkSliceReducerConfig<
6020
State,
6121
ThunkArg extends any,
@@ -155,6 +115,37 @@ export interface AsyncThunkCreator<
155115
>
156116
}
157117

118+
export type AsyncThunkCreatorExposes<
119+
State,
120+
CaseReducers extends CreatorCaseReducers<State>,
121+
> = {
122+
actions: {
123+
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
124+
State,
125+
infer ThunkArg,
126+
infer Returned,
127+
infer ThunkApiConfig
128+
>
129+
? AsyncThunk<Returned, ThunkArg, ThunkApiConfig>
130+
: never
131+
}
132+
caseReducers: {
133+
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
134+
State,
135+
any,
136+
any,
137+
any
138+
>
139+
? Id<
140+
Pick<
141+
Required<CaseReducers[ReducerName]>,
142+
'fulfilled' | 'rejected' | 'pending' | 'settled'
143+
>
144+
>
145+
: never
146+
}
147+
}
148+
158149
export const asyncThunkCreator: ReducerCreator<ReducerType.asyncThunk> = {
159150
type: ReducerType.asyncThunk,
160151
create: /* @__PURE__ */ (() => {

packages/toolkit/src/createSlice.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { Action, Reducer, UnknownAction } from 'redux'
22
import type { Selector } from 'reselect'
3+
import type {
4+
AsyncThunkCreator,
5+
AsyncThunkCreatorExposes,
6+
} from './asyncThunkCreator'
37
import type { InjectConfig } from './combineSlices'
48
import type {
59
ActionCreatorWithoutPayload,
@@ -9,20 +13,17 @@ import type {
913
_ActionCreatorWithPreparedPayload,
1014
} from './createAction'
1115
import { createAction } from './createAction'
12-
import type {
13-
AsyncThunk,
14-
AsyncThunkConfig,
15-
AsyncThunkOptions,
16-
AsyncThunkPayloadCreator,
17-
OverrideThunkApiConfigs,
18-
} from './createAsyncThunk'
1916
import { createAsyncThunk as _createAsyncThunk } from './createAsyncThunk'
2017
import type {
2118
ActionMatcherDescriptionCollection,
2219
CaseReducer,
2320
ReducerWithInitialState,
2421
} from './createReducer'
2522
import { createReducer, makeGetInitialState } from './createReducer'
23+
import type {
24+
EntityMethodsCreator,
25+
entityMethodsCreatorType,
26+
} from './entities/slice_creator'
2627
import type { ActionReducerMapBuilder, TypedActionCreator } from './mapBuilders'
2728
import { executeReducerBuilderCallback } from './mapBuilders'
2829
import type {
@@ -145,6 +146,11 @@ export interface SliceReducerCreators<
145146
}
146147
}
147148
>
149+
[ReducerType.asyncThunk]: ReducerCreatorEntry<
150+
AsyncThunkCreator<State>,
151+
AsyncThunkCreatorExposes<State, CaseReducers>
152+
>
153+
[entityMethodsCreatorType]: ReducerCreatorEntry<EntityMethodsCreator<State>>
148154
}
149155

150156
export type ReducerCreators<

packages/toolkit/src/entities/slice_creator.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type {
22
CaseReducerDefinition,
3-
CreatorCaseReducers,
43
PayloadAction,
54
ReducerCreator,
65
ReducerCreatorEntry,
@@ -30,7 +29,7 @@ export interface EntityMethodsCreatorConfig<
3029
pluralName?: Plural
3130
}
3231

33-
type EntityMethodsCreator<State> =
32+
export type EntityMethodsCreator<State> =
3433
State extends EntityState<infer T, infer Id>
3534
? {
3635
<
@@ -69,17 +68,6 @@ type EntityMethodsCreator<State> =
6968
>,
7069
) => EntityReducers<T, Id, State, Single, Plural>
7170

72-
declare module '@reduxjs/toolkit' {
73-
export interface SliceReducerCreators<
74-
State,
75-
CaseReducers extends CreatorCaseReducers<State>,
76-
Name extends string,
77-
ReducerPath extends string,
78-
> {
79-
[entityMethodsCreatorType]: ReducerCreatorEntry<EntityMethodsCreator<State>>
80-
}
81-
}
82-
8371
const makeWrappedReducerCreator =
8472
<T, Id extends EntityId, State>(
8573
selectEntityState: (state: State) => EntityState<T, Id>,

0 commit comments

Comments
 (0)