123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- import type { Reducer } from 'redux';
- import type { ActionCreatorWithoutPayload, PayloadAction, PayloadActionCreator, PrepareAction, _ActionCreatorWithPreparedPayload } from './createAction';
- import type { CaseReducer, CaseReducers } from './createReducer';
- import type { ActionReducerMapBuilder } from './mapBuilders';
- import type { NoInfer } from './tsHelpers';
- export declare type SliceActionCreator<P> = PayloadActionCreator<P>;
- export interface Slice<State = any, CaseReducers extends SliceCaseReducers<State> = SliceCaseReducers<State>, Name extends string = string> {
-
- name: Name;
-
- reducer: Reducer<State>;
-
- actions: CaseReducerActions<CaseReducers, Name>;
-
- caseReducers: SliceDefinedCaseReducers<CaseReducers>;
-
- getInitialState: () => State;
- }
- export interface CreateSliceOptions<State = any, CR extends SliceCaseReducers<State> = SliceCaseReducers<State>, Name extends string = string> {
-
- name: Name;
-
- initialState: State | (() => State);
-
- reducers: ValidateSliceCaseReducers<State, CR>;
-
- extraReducers?: CaseReducers<NoInfer<State>, any> | ((builder: ActionReducerMapBuilder<NoInfer<State>>) => void);
- }
- export declare type CaseReducerWithPrepare<State, Action extends PayloadAction> = {
- reducer: CaseReducer<State, Action>;
- prepare: PrepareAction<Action['payload']>;
- };
- export declare type SliceCaseReducers<State> = {
- [K: string]: CaseReducer<State, PayloadAction<any>> | CaseReducerWithPrepare<State, PayloadAction<any, string, any, any>>;
- };
- declare type SliceActionType<SliceName extends string, ActionName extends keyof any> = ActionName extends string | number ? `${SliceName}/${ActionName}` : string;
- export declare type CaseReducerActions<CaseReducers extends SliceCaseReducers<any>, SliceName extends string> = {
- [Type in keyof CaseReducers]: CaseReducers[Type] extends {
- prepare: any;
- } ? ActionCreatorForCaseReducerWithPrepare<CaseReducers[Type], SliceActionType<SliceName, Type>> : ActionCreatorForCaseReducer<CaseReducers[Type], SliceActionType<SliceName, Type>>;
- };
- declare type ActionCreatorForCaseReducerWithPrepare<CR extends {
- prepare: any;
- }, Type extends string> = _ActionCreatorWithPreparedPayload<CR['prepare'], Type>;
- declare type ActionCreatorForCaseReducer<CR, Type extends string> = CR extends (state: any, action: infer Action) => any ? Action extends {
- payload: infer P;
- } ? PayloadActionCreator<P, Type> : ActionCreatorWithoutPayload<Type> : ActionCreatorWithoutPayload<Type>;
- declare type SliceDefinedCaseReducers<CaseReducers extends SliceCaseReducers<any>> = {
- [Type in keyof CaseReducers]: CaseReducers[Type] extends {
- reducer: infer Reducer;
- } ? Reducer : CaseReducers[Type];
- };
- export declare type ValidateSliceCaseReducers<S, ACR extends SliceCaseReducers<S>> = ACR & {
- [T in keyof ACR]: ACR[T] extends {
- reducer(s: S, action?: infer A): any;
- } ? {
- prepare(...a: never[]): Omit<A, 'type'>;
- } : {};
- };
- export declare function createSlice<State, CaseReducers extends SliceCaseReducers<State>, Name extends string = string>(options: CreateSliceOptions<State, CaseReducers, Name>): Slice<State, CaseReducers, Name>;
- export {};
|