UNPKG

3.75 kBTypeScriptView Raw
1export interface Action {
2 type: string;
3}
4export declare interface TypedAction<T extends string> extends Action {
5 readonly type: T;
6}
7export declare type ActionType<A> = A extends ActionCreator<infer T, infer C> ? ReturnType<C> & {
8 type: T;
9} : never;
10export declare type TypeId<T> = () => T;
11export declare type InitialState<T> = Partial<T> | TypeId<Partial<T>> | void;
12/**
13 * A function that takes an `Action` and a `State`, and returns a `State`.
14 * See `createReducer`.
15 */
16export interface ActionReducer<T, V extends Action = Action> {
17 (state: T | undefined, action: V): T;
18}
19export declare type ActionReducerMap<T, V extends Action = Action> = {
20 [p in keyof T]: ActionReducer<T[p], V>;
21};
22export interface ActionReducerFactory<T, V extends Action = Action> {
23 (reducerMap: ActionReducerMap<T, V>, initialState?: InitialState<T>): ActionReducer<T, V>;
24}
25export declare type MetaReducer<T = any, V extends Action = Action> = (reducer: ActionReducer<T, V>) => ActionReducer<T, V>;
26export interface StoreFeature<T, V extends Action = Action> {
27 key: string;
28 reducers: ActionReducerMap<T, V> | ActionReducer<T, V>;
29 reducerFactory: ActionReducerFactory<T, V>;
30 initialState?: InitialState<T>;
31 metaReducers?: MetaReducer<T, V>[];
32}
33export declare type Selector<T, V> = (state: T) => V;
34export declare type SelectorWithProps<State, Props, Result> = (state: State, props: Props) => Result;
35export declare const arraysAreNotAllowedMsg = "arrays are not allowed in action creators";
36declare type ArraysAreNotAllowed = typeof arraysAreNotAllowedMsg;
37export declare const typePropertyIsNotAllowedMsg = "type property is not allowed in action creators";
38declare type TypePropertyIsNotAllowed = typeof typePropertyIsNotAllowedMsg;
39export declare const emptyObjectsAreNotAllowedMsg = "empty objects are not allowed in action creators";
40declare type EmptyObjectsAreNotAllowed = typeof emptyObjectsAreNotAllowedMsg;
41export declare type FunctionIsNotAllowed<T, ErrorMessage extends string> = T extends Function ? ErrorMessage : T;
42/**
43 * A function that returns an object in the shape of the `Action` interface. Configured using `createAction`.
44 */
45export declare type Creator<P extends any[] = any[], R extends object = object> = FunctionWithParametersType<P, R>;
46export declare type NotAllowedCheck<T extends object> = T extends any[] ? ArraysAreNotAllowed : T extends {
47 type: any;
48} ? TypePropertyIsNotAllowed : keyof T extends never ? EmptyObjectsAreNotAllowed : unknown;
49/**
50 * See `Creator`.
51 */
52export declare type ActionCreator<T extends string = string, C extends Creator = Creator> = C & TypedAction<T>;
53export interface ActionCreatorProps<T> {
54 _as: 'props';
55 _p: T;
56}
57export declare type FunctionWithParametersType<P extends unknown[], R = void> = (...args: P) => R;
58export declare type ParametersType<T> = T extends (...args: infer U) => unknown ? U : never;
59export interface RuntimeChecks {
60 /**
61 * Verifies if the state is serializable
62 */
63 strictStateSerializability: boolean;
64 /**
65 * Verifies if the actions are serializable. Please note, you may not need to set it to `true` unless you are storing/replaying actions using external resources, for example `localStorage`.
66 */
67 strictActionSerializability: boolean;
68 /**
69 * Verifies that the state isn't mutated
70 */
71 strictStateImmutability: boolean;
72 /**
73 * Verifies that actions aren't mutated
74 */
75 strictActionImmutability: boolean;
76 /**
77 * Verifies that actions are dispatched within NgZone
78 */
79 strictActionWithinNgZone: boolean;
80 /**
81 * Verifies that action types are not registered more than once
82 */
83 strictActionTypeUniqueness?: boolean;
84}
85export {};