envoc-hook-local-slice
Version:
envoc-table
26 lines (25 loc) • 1.39 kB
TypeScript
import { Draft } from 'immer';
export declare type ActionWithPayload<P> = {
type: string;
payload: P;
};
export declare type ActionDispatch<P = void> = void extends P ? () => void : (payload: P) => void;
export declare type ReducerWithoutPayload<S> = (state: Draft<S>) => void;
export declare type Reducer<S, P = void> = (state: Draft<S>, payload: P) => void;
export declare type PromiseReducer<S, P = void, D = void> = {
pending: (state: Draft<S>, payload: P, abortSignal: AbortSignal) => Promise<D>;
resolved?: (state: Draft<S>, payload: P, resp: D) => void;
rejected?: (state: Draft<S>, payload: P, error: any) => void;
finally?: (state: Draft<S>, payload: P) => void;
};
export declare type ReducerMap<State> = {
[actionType: string]: Reducer<State, any> | PromiseReducer<State, any, any>;
};
export declare type DispatcherMap<Reducers extends ReducerMap<any>> = {
[T in keyof Reducers]: Reducers[T] extends PromiseReducer<any> ? ActionDispatch<void> : Reducers[T] extends PromiseReducer<any, infer P, any> ? ActionDispatch<P> : Reducers[T] extends ReducerWithoutPayload<any> ? ActionDispatch<void> : Reducers[T] extends Reducer<any, infer P> ? ActionDispatch<P> : never;
};
export interface UseLocalSliceProps<State, Reducers extends ReducerMap<State>> {
initialState: State;
reducers: Reducers;
slice?: string;
}