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 11b873c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 40 deletions.
56 changes: 25 additions & 31 deletions packages/toolkit/src/asyncThunkCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { CaseReducer } from './createReducer'
import type {
CreatorCaseReducers,
ReducerCreator,
ReducerCreatorEntry,
ReducerDefinition,
} from './createSlice'
import { ReducerType } from './createSlice'
Expand Down Expand Up @@ -115,40 +114,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
5 changes: 0 additions & 5 deletions packages/toolkit/src/entities/slice_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type {
CaseReducerDefinition,
PayloadAction,
ReducerCreator,
ReducerCreatorEntry,
} from '@reduxjs/toolkit'
import { reducerCreator } from '../createSlice'
import type { WithRequiredProp } from '../tsHelpers'
Expand Down Expand Up @@ -68,10 +67,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 11b873c

Please sign in to comment.