Skip to content

Commit

Permalink
move async thunk creator module augmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 committed May 22, 2024
1 parent 15f01b9 commit d976ea5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 36 deletions.
48 changes: 47 additions & 1 deletion packages/toolkit/src/asyncThunkCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,54 @@ import type {
} from './createAsyncThunk'
import { createAsyncThunk } from './createAsyncThunk'
import type { CaseReducer } from './createReducer'
import type { ReducerCreator, ReducerDefinition } from './createSlice'
import type {
CreatorCaseReducers,
ReducerCreator,
ReducerCreatorEntry,
ReducerDefinition,
} from './createSlice'
import { ReducerType } from './createSlice'
import type { Id } from './tsHelpers'

declare module '@reduxjs/toolkit' {
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 interface AsyncThunkSliceReducerConfig<
State,
Expand Down
35 changes: 0 additions & 35 deletions packages/toolkit/src/createSlice.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { Action, UnknownAction, Reducer } from 'redux'
import type { Selector } from 'reselect'
import type {
AsyncThunkCreator,
AsyncThunkSliceReducerDefinition,
} from './asyncThunkCreator'
import type {
ActionCreatorWithoutPayload,
PayloadAction,
Expand All @@ -12,7 +8,6 @@ import type {
_ActionCreatorWithPreparedPayload,
} from './createAction'
import { createAction } from './createAction'
import type { AsyncThunk } from './createAsyncThunk'
import type {
ActionMatcherDescriptionCollection,
CaseReducer,
Expand Down Expand Up @@ -135,36 +130,6 @@ export interface SliceReducerCreators<
}
}
>
[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 ReducerCreators<
Expand Down

0 comments on commit d976ea5

Please sign in to comment.