Skip to content

Commit

Permalink
fix creator issue
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 committed Sep 3, 2024
1 parent 88fa75f commit ed623ac
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 38 deletions.
55 changes: 25 additions & 30 deletions packages/toolkit/src/asyncThunkCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,40 +115,35 @@ export interface AsyncThunkCreator<
>
}

export type AsyncThunkCreators<
export type AsyncThunkCreatorExposes<
State,
CaseReducers extends CreatorCaseReducers<State>,
> = {
[ReducerType.asyncThunk]: ReducerCreatorEntry<
AsyncThunkCreator<State>,
{
actions: {
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
State,
infer ThunkArg,
infer Returned,
infer ThunkApiConfig
>
? AsyncThunk<Returned, ThunkArg, ThunkApiConfig>
: never
}
caseReducers: {
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
State,
any,
any,
any
actions: {
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
State,
infer ThunkArg,
infer Returned,
infer ThunkApiConfig
>
? AsyncThunk<Returned, ThunkArg, ThunkApiConfig>
: never
}
caseReducers: {
[ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition<
State,
any,
any,
any
>
? Id<
Pick<
Required<CaseReducers[ReducerName]>,
'fulfilled' | 'rejected' | 'pending' | 'settled'
>
>
? Id<
Pick<
Required<CaseReducers[ReducerName]>,
'fulfilled' | 'rejected' | 'pending' | 'settled'
>
>
: never
}
}
>
: never
}
}

export const asyncThunkCreator: ReducerCreator<ReducerType.asyncThunk> = {
Expand Down
18 changes: 14 additions & 4 deletions packages/toolkit/src/createSlice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { Action, Reducer, UnknownAction } from 'redux'
import type { Selector } from 'reselect'
import type { AsyncThunkCreators } from './asyncThunkCreator'
import type {
AsyncThunkCreator,
AsyncThunkCreatorExposes,
} from './asyncThunkCreator'
import type { InjectConfig } from './combineSlices'
import type {
ActionCreatorWithoutPayload,
Expand All @@ -17,7 +20,10 @@ import type {
ReducerWithInitialState,
} from './createReducer'
import { createReducer, makeGetInitialState } from './createReducer'
import type { EntityCreators } from './entities/slice_creator'
import type {
EntityMethodsCreator,
entityMethodsCreatorType,
} from './entities/slice_creator'
import type { ActionReducerMapBuilder, TypedActionCreator } from './mapBuilders'
import { executeReducerBuilderCallback } from './mapBuilders'
import type {
Expand Down Expand Up @@ -74,8 +80,7 @@ export interface SliceReducerCreators<
CaseReducers extends CreatorCaseReducers<State>,
Name extends string,
ReducerPath extends string,
> extends AsyncThunkCreators<State, CaseReducers>,
EntityCreators<State> {
> {
[ReducerType.reducer]: ReducerCreatorEntry<
{
(
Expand Down Expand Up @@ -141,6 +146,11 @@ export interface SliceReducerCreators<
}
}
>
[ReducerType.asyncThunk]: ReducerCreatorEntry<
AsyncThunkCreator<State>,
AsyncThunkCreatorExposes<State, CaseReducers>
>
[entityMethodsCreatorType]: ReducerCreatorEntry<EntityMethodsCreator<State>>
}

export type ReducerCreators<
Expand Down
4 changes: 0 additions & 4 deletions packages/toolkit/src/entities/slice_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ export type EntityMethodsCreator<State> =
>,
) => EntityReducers<T, Id, State, Single, Plural>

export type EntityCreators<State> = {
[entityMethodsCreatorType]: ReducerCreatorEntry<EntityMethodsCreator<State>>
}

const makeWrappedReducerCreator =
<T, Id extends EntityId, State>(
selectEntityState: (state: State) => EntityState<T, Id>,
Expand Down

0 comments on commit ed623ac

Please sign in to comment.