@anhnh27/reduxtoolkit-action-dispatcher
Version:
Dispatch redux actions without useDispatch or mapDispatchToProps
21 lines (20 loc) • 1.76 kB
TypeScript
import { ActionCreatorWithoutPayload, AnyAction, PayloadActionCreator, SliceCaseReducers } from "@reduxjs/toolkit";
import { ActionCreatorWithPayload, ActionCreatorWithPreparedPayload, _ActionCreatorWithPreparedPayload } from "@reduxjs/toolkit/dist/createAction";
declare type PromiseResult = {
$result: any;
};
declare type ActionCreatorForCaseReducerWithPrepare<CR extends {
prepare: any;
}, Type extends string> = _ActionCreatorWithPreparedPayload<CR["prepare"], Type>;
export 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>>;
};
export 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>;
export declare type ActionCreator<Name extends string, CaseReducers> = void | ActionCreatorWithPreparedPayload<unknown[], unknown, SliceActionType<Name, Extract<keyof CaseReducers, string>>, unknown, unknown> | ActionCreatorWithoutPayload<any> | ActionCreatorWithPayload<any>;
export declare type DispatchFunction<Type extends string, CR> = (...payload: Parameters<ActionCreatorForCaseReducer<CR, Type>>) => AnyAction & PromiseResult;
export {};