Skip to content

Commit 11b873c

Browse files
committed
fix creator issue
1 parent 88fa75f commit 11b873c

File tree

3 files changed

+39
-40
lines changed

3 files changed

+39
-40
lines changed

packages/toolkit/src/asyncThunkCreator.ts

+25-31
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type { CaseReducer } from './createReducer'
1010
import type {
1111
CreatorCaseReducers,
1212
ReducerCreator,
13-
ReducerCreatorEntry,
1413
ReducerDefinition,
1514
} from './createSlice'
1615
import { ReducerType } from './createSlice'
@@ -115,40 +114,35 @@ export interface AsyncThunkCreator<
115114
>
116115
}
117116

118-
export type AsyncThunkCreators<
117+
export type AsyncThunkCreatorExposes<
119118
State,
120119
CaseReducers extends CreatorCaseReducers<State>,
121120
> = {
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
121+
actions: {
122+
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
123+
State,
124+
infer ThunkArg,
125+
infer Returned,
126+
infer ThunkApiConfig
127+
>
128+
? AsyncThunk<Returned, ThunkArg, ThunkApiConfig>
129+
: never
130+
}
131+
caseReducers: {
132+
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
133+
State,
134+
any,
135+
any,
136+
any
137+
>
138+
? Id<
139+
Pick<
140+
Required<CaseReducers[ReducerName]>,
141+
'fulfilled' | 'rejected' | 'pending' | 'settled'
142+
>
141143
>
142-
? Id<
143-
Pick<
144-
Required<CaseReducers[ReducerName]>,
145-
'fulfilled' | 'rejected' | 'pending' | 'settled'
146-
>
147-
>
148-
: never
149-
}
150-
}
151-
>
144+
: never
145+
}
152146
}
153147

154148
export const asyncThunkCreator: ReducerCreator<ReducerType.asyncThunk> = {

packages/toolkit/src/createSlice.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { Action, Reducer, UnknownAction } from 'redux'
22
import type { Selector } from 'reselect'
3-
import type { AsyncThunkCreators } from './asyncThunkCreator'
3+
import type {
4+
AsyncThunkCreator,
5+
AsyncThunkCreatorExposes,
6+
} from './asyncThunkCreator'
47
import type { InjectConfig } from './combineSlices'
58
import type {
69
ActionCreatorWithoutPayload,
@@ -17,7 +20,10 @@ import type {
1720
ReducerWithInitialState,
1821
} from './createReducer'
1922
import { createReducer, makeGetInitialState } from './createReducer'
20-
import type { EntityCreators } from './entities/slice_creator'
23+
import type {
24+
EntityMethodsCreator,
25+
entityMethodsCreatorType,
26+
} from './entities/slice_creator'
2127
import type { ActionReducerMapBuilder, TypedActionCreator } from './mapBuilders'
2228
import { executeReducerBuilderCallback } from './mapBuilders'
2329
import type {
@@ -74,8 +80,7 @@ export interface SliceReducerCreators<
7480
CaseReducers extends CreatorCaseReducers<State>,
7581
Name extends string,
7682
ReducerPath extends string,
77-
> extends AsyncThunkCreators<State, CaseReducers>,
78-
EntityCreators<State> {
83+
> {
7984
[ReducerType.reducer]: ReducerCreatorEntry<
8085
{
8186
(
@@ -141,6 +146,11 @@ export interface SliceReducerCreators<
141146
}
142147
}
143148
>
149+
[ReducerType.asyncThunk]: ReducerCreatorEntry<
150+
AsyncThunkCreator<State>,
151+
AsyncThunkCreatorExposes<State, CaseReducers>
152+
>
153+
[entityMethodsCreatorType]: ReducerCreatorEntry<EntityMethodsCreator<State>>
144154
}
145155

146156
export type ReducerCreators<

packages/toolkit/src/entities/slice_creator.ts

-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type {
22
CaseReducerDefinition,
33
PayloadAction,
44
ReducerCreator,
5-
ReducerCreatorEntry,
65
} from '@reduxjs/toolkit'
76
import { reducerCreator } from '../createSlice'
87
import type { WithRequiredProp } from '../tsHelpers'
@@ -68,10 +67,6 @@ export type EntityMethodsCreator<State> =
6867
>,
6968
) => EntityReducers<T, Id, State, Single, Plural>
7069

71-
export type EntityCreators<State> = {
72-
[entityMethodsCreatorType]: ReducerCreatorEntry<EntityMethodsCreator<State>>
73-
}
74-
7570
const makeWrappedReducerCreator =
7671
<T, Id extends EntityId, State>(
7772
selectEntityState: (state: State) => EntityState<T, Id>,

0 commit comments

Comments
 (0)