From ef2d0242b227d949d83fdc7de3cfd06d7a2db247 Mon Sep 17 00:00:00 2001 From: Ben Durrant Date: Tue, 3 Sep 2024 10:12:10 +0100 Subject: [PATCH] avoid relative declaration --- packages/toolkit/src/asyncThunkCreator.ts | 64 ++++++++++------------- packages/toolkit/src/createSlice.ts | 15 +++--- 2 files changed, 35 insertions(+), 44 deletions(-) diff --git a/packages/toolkit/src/asyncThunkCreator.ts b/packages/toolkit/src/asyncThunkCreator.ts index 198fb3a1c9..a2a974a1bf 100644 --- a/packages/toolkit/src/asyncThunkCreator.ts +++ b/packages/toolkit/src/asyncThunkCreator.ts @@ -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, - Name extends string, - ReducerPath extends string, - > { - [ReducerType.asyncThunk]: ReducerCreatorEntry< - AsyncThunkCreator, - { - actions: { - [ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition< - State, - infer ThunkArg, - infer Returned, - infer ThunkApiConfig - > - ? AsyncThunk - : never - } - caseReducers: { - [ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition< - State, - any, - any, - any - > - ? Id< - Pick< - Required, - 'fulfilled' | 'rejected' | 'pending' | 'settled' - > - > - : never - } - } +export type AsyncThunkCreatorExposes< + State, + CaseReducers extends CreatorCaseReducers, +> = { + actions: { + [ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition< + State, + infer ThunkArg, + infer Returned, + infer ThunkApiConfig > + ? AsyncThunk + : never + } + caseReducers: { + [ReducerName in keyof CaseReducers]: CaseReducers[ReducerName] extends AsyncThunkSliceReducerDefinition< + State, + any, + any, + any + > + ? Id< + Pick< + Required, + 'fulfilled' | 'rejected' | 'pending' | 'settled' + > + > + : never } } diff --git a/packages/toolkit/src/createSlice.ts b/packages/toolkit/src/createSlice.ts index 54d5a0ac3d..76dfeeb730 100644 --- a/packages/toolkit/src/createSlice.ts +++ b/packages/toolkit/src/createSlice.ts @@ -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, @@ -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, @@ -145,6 +142,10 @@ export interface SliceReducerCreators< } } > + [ReducerType.asyncThunk]: ReducerCreatorEntry< + AsyncThunkCreator, + AsyncThunkCreatorExposes + > } export type ReducerCreators<