Skip to content

Commit 7252c16

Browse files
committed
move module augmentation back to createSlice
1 parent 09cc0c7 commit 7252c16

File tree

2 files changed

+43
-54
lines changed

2 files changed

+43
-54
lines changed

packages/toolkit/src/asyncThunkCreator.ts

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
import type {
2-
ReducerNamesOfType,
3-
ReducerCreatorEntry,
4-
ReducerCreator,
5-
ReducerDefinition,
6-
CreatorCaseReducers,
7-
} from '@reduxjs/toolkit'
81
import type {
92
AsyncThunk,
103
AsyncThunkConfig,
@@ -14,53 +7,8 @@ import type {
147
} from './createAsyncThunk'
158
import { createAsyncThunk } from './createAsyncThunk'
169
import type { CaseReducer } from './createReducer'
10+
import type { ReducerCreator, ReducerDefinition } from './createSlice'
1711
import { ReducerType } from './createSlice'
18-
import type { Id } from './tsHelpers'
19-
20-
declare module '@reduxjs/toolkit' {
21-
export interface SliceReducerCreators<
22-
State,
23-
CaseReducers extends CreatorCaseReducers<State>,
24-
Name extends string,
25-
> {
26-
[ReducerType.asyncThunk]: ReducerCreatorEntry<
27-
AsyncThunkCreator<State>,
28-
{
29-
actions: {
30-
[ReducerName in ReducerNamesOfType<
31-
CaseReducers,
32-
ReducerType.asyncThunk
33-
>]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
34-
State,
35-
infer ThunkArg,
36-
infer Returned,
37-
infer ThunkApiConfig
38-
>
39-
? AsyncThunk<Returned, ThunkArg, ThunkApiConfig>
40-
: never
41-
}
42-
caseReducers: {
43-
[ReducerName in ReducerNamesOfType<
44-
CaseReducers,
45-
ReducerType.asyncThunk
46-
>]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
47-
State,
48-
any,
49-
any,
50-
any
51-
>
52-
? Id<
53-
Pick<
54-
Required<CaseReducers[ReducerName]>,
55-
'fulfilled' | 'rejected' | 'pending' | 'settled'
56-
>
57-
>
58-
: never
59-
}
60-
}
61-
>
62-
}
63-
}
6412

6513
export interface AsyncThunkSliceReducerConfig<
6614
State,
@@ -113,7 +61,7 @@ type PreventCircular<ThunkApiConfig> = {
11361
: ThunkApiConfig[K]
11462
}
11563

116-
interface AsyncThunkCreator<
64+
export interface AsyncThunkCreator<
11765
State,
11866
CurriedThunkApiConfig extends
11967
PreventCircular<AsyncThunkConfig> = PreventCircular<AsyncThunkConfig>,

packages/toolkit/src/createSlice.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { Action, UnknownAction, Reducer } from 'redux'
22
import type { Selector } from 'reselect'
3+
import type {
4+
AsyncThunkCreator,
5+
AsyncThunkSliceReducerDefinition,
6+
} from './asyncThunkCreator'
37
import type {
48
ActionCreatorWithoutPayload,
59
PayloadAction,
@@ -8,6 +12,7 @@ import type {
812
_ActionCreatorWithPreparedPayload,
913
} from './createAction'
1014
import { createAction } from './createAction'
15+
import type { AsyncThunk } from './createAsyncThunk'
1116
import type {
1217
ActionMatcherDescriptionCollection,
1318
CaseReducer,
@@ -124,6 +129,42 @@ export interface SliceReducerCreators<
124129
}
125130
}
126131
>
132+
[ReducerType.asyncThunk]: ReducerCreatorEntry<
133+
AsyncThunkCreator<State>,
134+
{
135+
actions: {
136+
[ReducerName in ReducerNamesOfType<
137+
CaseReducers,
138+
ReducerType.asyncThunk
139+
>]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
140+
State,
141+
infer ThunkArg,
142+
infer Returned,
143+
infer ThunkApiConfig
144+
>
145+
? AsyncThunk<Returned, ThunkArg, ThunkApiConfig>
146+
: never
147+
}
148+
caseReducers: {
149+
[ReducerName in ReducerNamesOfType<
150+
CaseReducers,
151+
ReducerType.asyncThunk
152+
>]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
153+
State,
154+
any,
155+
any,
156+
any
157+
>
158+
? Id<
159+
Pick<
160+
Required<CaseReducers[ReducerName]>,
161+
'fulfilled' | 'rejected' | 'pending' | 'settled'
162+
>
163+
>
164+
: never
165+
}
166+
}
167+
>
127168
}
128169

129170
export type ReducerCreators<

0 commit comments

Comments
 (0)