ngrx-handlers
Version:
NgRx Plugin for Generating Actions and Reducer Based on the Handler Map
26 lines (25 loc) • 1.96 kB
TypeScript
import { ActionCreator as TypedActionCreator } from '@ngrx/store';
declare type ArraysAreNotAllowed = 'arrays are not allowed in action creators';
declare type TypePropertyIsNotAllowed = 'type property is not allowed in action creators';
declare type PrimitivesAreNotAllowed = 'primitive types are not allowed in action creators';
declare type NullOrUndefinedAreNotAllowed = 'null or undefined are not allowed in action creators';
declare type EmptyObjectsAreNotAllowed = 'empty objects are not allowed in action creators';
declare type Primitive = number | bigint | string | boolean;
declare type NullOrUndefined = null | undefined;
export declare type TypedAction = {
readonly type: string;
};
export declare type PlainCaseReducer<State> = (state: State) => State;
export declare type CaseReducer<State, Payload> = (state: State, payload: Payload) => State;
export declare type PlainActionCreator = () => TypedAction;
export declare type ActionCreatorWithPayload<Payload> = (payload: Payload) => Payload & TypedAction;
export declare type ActionCreator<State, Reducer> = Reducer extends PlainCaseReducer<State> ? PlainActionCreator : Reducer extends CaseReducer<State, infer Payload> ? Payload extends any[] ? ActionCreatorWithPayload<ArraysAreNotAllowed> : Payload extends {
type: any;
} ? ActionCreatorWithPayload<TypePropertyIsNotAllowed> : Payload extends Primitive ? ActionCreatorWithPayload<PrimitivesAreNotAllowed> : Payload extends NullOrUndefined ? ActionCreatorWithPayload<NullOrUndefinedAreNotAllowed> : keyof Payload extends never ? ActionCreatorWithPayload<EmptyObjectsAreNotAllowed> : ActionCreatorWithPayload<Payload> : never;
export declare type HandlerMap<State> = {
[event: string]: CaseReducer<State, any>;
};
export declare type ActionMap<State, Handlers extends HandlerMap<State>> = {
[Event in keyof Handlers]: TypedActionCreator<string, ActionCreator<State, Handlers[Event]>>;
};
export {};