From 11b873c02032f48415f558cab4e89946f9aecd9e Mon Sep 17 00:00:00 2001 From: Ben Durrant Date: Tue, 3 Sep 2024 10:28:55 +0100 Subject: [PATCH] fix creator issue --- packages/toolkit/src/asyncThunkCreator.ts | 56 +++++++++---------- packages/toolkit/src/createSlice.ts | 18 ++++-- .../toolkit/src/entities/slice_creator.ts | 5 -- 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/packages/toolkit/src/asyncThunkCreator.ts b/packages/toolkit/src/asyncThunkCreator.ts index b7e9ec7cb7..19fb0380ac 100644 --- a/packages/toolkit/src/asyncThunkCreator.ts +++ b/packages/toolkit/src/asyncThunkCreator.ts @@ -10,7 +10,6 @@ import type { CaseReducer } from './createReducer' import type { CreatorCaseReducers, ReducerCreator, - ReducerCreatorEntry, ReducerDefinition, } from './createSlice' import { ReducerType } from './createSlice' @@ -115,40 +114,35 @@ export interface AsyncThunkCreator< > } -export type AsyncThunkCreators< +export type AsyncThunkCreatorExposes< State, CaseReducers extends CreatorCaseReducers, > = { - [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 + 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' + > > - ? Id< - Pick< - Required, - 'fulfilled' | 'rejected' | 'pending' | 'settled' - > - > - : never - } - } - > + : never + } } export const asyncThunkCreator: ReducerCreator = { diff --git a/packages/toolkit/src/createSlice.ts b/packages/toolkit/src/createSlice.ts index dcf3ee98a3..5bf5c9744c 100644 --- a/packages/toolkit/src/createSlice.ts +++ b/packages/toolkit/src/createSlice.ts @@ -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, @@ -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 { @@ -74,8 +80,7 @@ export interface SliceReducerCreators< CaseReducers extends CreatorCaseReducers, Name extends string, ReducerPath extends string, -> extends AsyncThunkCreators, - EntityCreators { +> { [ReducerType.reducer]: ReducerCreatorEntry< { ( @@ -141,6 +146,11 @@ export interface SliceReducerCreators< } } > + [ReducerType.asyncThunk]: ReducerCreatorEntry< + AsyncThunkCreator, + AsyncThunkCreatorExposes + > + [entityMethodsCreatorType]: ReducerCreatorEntry> } export type ReducerCreators< diff --git a/packages/toolkit/src/entities/slice_creator.ts b/packages/toolkit/src/entities/slice_creator.ts index b1fbe29903..d1fa780985 100644 --- a/packages/toolkit/src/entities/slice_creator.ts +++ b/packages/toolkit/src/entities/slice_creator.ts @@ -2,7 +2,6 @@ import type { CaseReducerDefinition, PayloadAction, ReducerCreator, - ReducerCreatorEntry, } from '@reduxjs/toolkit' import { reducerCreator } from '../createSlice' import type { WithRequiredProp } from '../tsHelpers' @@ -68,10 +67,6 @@ export type EntityMethodsCreator = >, ) => EntityReducers -export type EntityCreators = { - [entityMethodsCreatorType]: ReducerCreatorEntry> -} - const makeWrappedReducerCreator = ( selectEntityState: (state: State) => EntityState,