Skip to content

Commit

Permalink
Merge branch 'create-slice-creators' into entity-methods-creator
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 committed Sep 3, 2024
2 parents 45de908 + ef2d024 commit 90a7737
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 44 deletions.
64 changes: 27 additions & 37 deletions packages/toolkit/src/asyncThunkCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,39 @@ import type { CaseReducer } from './createReducer'
import type {
CreatorCaseReducers,
ReducerCreator,
ReducerCreatorEntry,
ReducerDefinition,
} from './createSlice'
import { ReducerType } from './createSlice'
import type { Id } from './tsHelpers'

declare module './createSlice' {
export interface SliceReducerCreators<
State,
CaseReducers extends CreatorCaseReducers<State>,
Name extends string,
ReducerPath extends string,
> {
[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
>
? Id<
Pick<
Required<CaseReducers[ReducerName]>,
'fulfilled' | 'rejected' | 'pending' | 'settled'
>
>
: never
}
}
export type AsyncThunkCreatorExposes<
State,
CaseReducers extends CreatorCaseReducers<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
>
? Id<
Pick<
Required<CaseReducers[ReducerName]>,
'fulfilled' | 'rejected' | 'pending' | 'settled'
>
>
: never
}
}

Expand Down
15 changes: 8 additions & 7 deletions packages/toolkit/src/createSlice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { Action, Reducer, UnknownAction } from 'redux'
import type { Selector } from 'reselect'
import type {
AsyncThunkCreator,
AsyncThunkCreatorExposes,
} from './asyncThunkCreator'
import type { InjectConfig } from './combineSlices'
import type {
ActionCreatorWithoutPayload,
Expand All @@ -9,13 +13,6 @@ import type {
_ActionCreatorWithPreparedPayload,
} from './createAction'
import { createAction } from './createAction'
import type {
AsyncThunk,
AsyncThunkConfig,
AsyncThunkOptions,
AsyncThunkPayloadCreator,
OverrideThunkApiConfigs,
} from './createAsyncThunk'
import { createAsyncThunk as _createAsyncThunk } from './createAsyncThunk'
import type {
ActionMatcherDescriptionCollection,
Expand Down Expand Up @@ -145,6 +142,10 @@ export interface SliceReducerCreators<
}
}
>
[ReducerType.asyncThunk]: ReducerCreatorEntry<
AsyncThunkCreator<State>,
AsyncThunkCreatorExposes<State, CaseReducers>
>
}

export type ReducerCreators<
Expand Down

0 comments on commit 90a7737

Please sign in to comment.