import { Draft } from "immer"; /** get function arguments as tuple type */ declare type ArgumentsType = T extends (...args: infer V) => any ? V : never; /** * Get the first value of tuple when the tuple length is 1 otherwise return the * whole tuple */ declare type FirstOrAll = T extends [infer V] ? V : T; /** Get union of function property names */ declare type FunctionPropertyNames = { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]; declare type MethodObject = { [key: string]: () => any; }; /** Pick only methods from object */ declare type Methods = Pick>; /** flatten functions in an object to their return values */ declare type FlattenToReturnTypes = { [K in keyof T]: ReturnType; }; /** get union of object value types */ declare type ObjectValueTypes = T[keyof T]; /** get union of object method return types */ declare type ReturnTypeUnion = ObjectValueTypes>; /** * Get union of actions types from a ImmerReducer class */ export declare type Actions = ReturnTypeUnion>; /** type constraint for the ImmerReducer class */ export interface ImmerReducerClass { customName?: string; new (...args: any[]): ImmerReducer; } /** get state type from a ImmerReducer subclass */ export declare type ImmerReducerState = T extends { prototype: { state: infer V; }; } ? V : never; /** generate reducer function type from the ImmerReducer class */ export interface ImmerReducerFunction { (state: ImmerReducerState | undefined, action: ReturnTypeUnion>): ImmerReducerState; } /** ActionCreator function interface with actual action type name */ interface ImmerActionCreator { readonly type: ActionTypeType; (...args: Payload): { type: ActionTypeType; payload: FirstOrAll; }; } /** generate ActionCreators types from the ImmerReducer class */ export declare type ActionCreators = { [K in keyof Methods>]: ImmerActionCreator[K]>>; }; /** * Type guard for detecting actions created by immer reducer * * @param action any redux action * @param immerActionCreator method from a ImmerReducer class */ export declare function isAction>(action: { type: any; }, immerActionCreator: A): action is ReturnType; export declare function isActionFrom(action: { type: any; }, immerReducerClass: T): action is Actions; interface Reducer { (state: State | undefined, action: any): State; } /** * Combine multiple reducers into a single one * * @param reducers two or more reducer */ export declare function composeReducers(...reducers: Reducer[]): Reducer; /** The actual ImmerReducer class */ export declare class ImmerReducer { static customName?: string; readonly state: T; draftState: Draft; constructor(draftState: Draft, state: T); } export declare function createActionCreators(immerReducerClass: T): ActionCreators; export declare function createReducerFunction(immerReducerClass: T, initialState?: ImmerReducerState): ImmerReducerFunction; export declare function setPrefix(prefix: string): void; /** * INTERNAL! This is only for tests! */ export declare function _clearKnownClasses(): void; export {};