Skip to content

Commit 88fa75f

Browse files
committed
avoid declare module issue
1 parent 90a7737 commit 88fa75f

File tree

3 files changed

+44
-51
lines changed

3 files changed

+44
-51
lines changed

packages/toolkit/src/asyncThunkCreator.ts

+37-31
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,12 @@ import type { CaseReducer } from './createReducer'
1010
import type {
1111
CreatorCaseReducers,
1212
ReducerCreator,
13+
ReducerCreatorEntry,
1314
ReducerDefinition,
1415
} from './createSlice'
1516
import { ReducerType } from './createSlice'
1617
import type { Id } from './tsHelpers'
1718

18-
export type AsyncThunkCreatorExposes<
19-
State,
20-
CaseReducers extends CreatorCaseReducers<State>,
21-
> = {
22-
actions: {
23-
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
24-
State,
25-
infer ThunkArg,
26-
infer Returned,
27-
infer ThunkApiConfig
28-
>
29-
? AsyncThunk<Returned, ThunkArg, ThunkApiConfig>
30-
: never
31-
}
32-
caseReducers: {
33-
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
34-
State,
35-
any,
36-
any,
37-
any
38-
>
39-
? Id<
40-
Pick<
41-
Required<CaseReducers[ReducerName]>,
42-
'fulfilled' | 'rejected' | 'pending' | 'settled'
43-
>
44-
>
45-
: never
46-
}
47-
}
48-
4919
export type AsyncThunkSliceReducerConfig<
5020
State,
5121
ThunkArg extends any,
@@ -145,6 +115,42 @@ export interface AsyncThunkCreator<
145115
>
146116
}
147117

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

packages/toolkit/src/createSlice.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import type { Action, Reducer, UnknownAction } from 'redux'
22
import type { Selector } from 'reselect'
3-
import type {
4-
AsyncThunkCreator,
5-
AsyncThunkCreatorExposes,
6-
} from './asyncThunkCreator'
3+
import type { AsyncThunkCreators } from './asyncThunkCreator'
74
import type { InjectConfig } from './combineSlices'
85
import type {
96
ActionCreatorWithoutPayload,
@@ -20,6 +17,7 @@ import type {
2017
ReducerWithInitialState,
2118
} from './createReducer'
2219
import { createReducer, makeGetInitialState } from './createReducer'
20+
import type { EntityCreators } from './entities/slice_creator'
2321
import type { ActionReducerMapBuilder, TypedActionCreator } from './mapBuilders'
2422
import { executeReducerBuilderCallback } from './mapBuilders'
2523
import type {
@@ -76,7 +74,8 @@ export interface SliceReducerCreators<
7674
CaseReducers extends CreatorCaseReducers<State>,
7775
Name extends string,
7876
ReducerPath extends string,
79-
> {
77+
> extends AsyncThunkCreators<State, CaseReducers>,
78+
EntityCreators<State> {
8079
[ReducerType.reducer]: ReducerCreatorEntry<
8180
{
8281
(
@@ -142,10 +141,6 @@ export interface SliceReducerCreators<
142141
}
143142
}
144143
>
145-
[ReducerType.asyncThunk]: ReducerCreatorEntry<
146-
AsyncThunkCreator<State>,
147-
AsyncThunkCreatorExposes<State, CaseReducers>
148-
>
149144
}
150145

151146
export type ReducerCreators<

packages/toolkit/src/entities/slice_creator.ts

+3-11
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,15 +68,8 @@ 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-
}
71+
export type EntityCreators<State> = {
72+
[entityMethodsCreatorType]: ReducerCreatorEntry<EntityMethodsCreator<State>>
8173
}
8274

8375
const makeWrappedReducerCreator =

0 commit comments

Comments
 (0)