import { ComponentType, CSSProperties, Dispatch, ReactNode, RefObject } from 'react'; import { IfMaybeUndefined, IfVoid, IsAny, IsUnknownOrNonInferrable } from './utils/tsHelpers'; /** * Represent a generic function. * Used internally to improve code readability */ export type GenericFunction = (...args: any[]) => any; /** * Typed generic callback function, used mostly internally * to defined callback setters */ export type SomeCallback = (...args: TArgs[]) => TResult; /** * A callback setter is generally used to set the value of * a callback that will be used to perform updates */ export type CallbackSetter = (nextCallback: SomeCallback) => void; export type _ActionCreatorWithPreparedPayload | void, T extends string = string> = PA extends PrepareAction ? ActionCreatorWithPreparedPayload, P, T, ReturnType extends { error: infer E; } ? E : never, ReturnType extends { meta: infer M; } ? M : never> : void; export interface ActionCreatorWithNonInferrablePayload extends BaseActionCreator { (payload: PT): PayloadAction; } export interface ActionCreatorWithOptionalPayload extends BaseActionCreator { (payload?: P): PayloadAction; } export interface ActionCreatorWithoutPayload extends BaseActionCreator { (): PayloadAction; } export interface ActionCreatorWithPayload extends BaseActionCreator { (payload: P): PayloadAction; } export interface ActionCreatorWithPreparedPayload extends BaseActionCreator { /** * Calling this {@link redux#ActionCreator} with `Args` will return * an Action with a payload of type `P` and (depending on the `PrepareAction` * method used) a `meta`- and `error` property of types `M` and `E` respectively. */ (...args: Args): PayloadAction; } export type ActionPayload

= { payload: P; }; export interface BaseActionCreator { type: T; match: (action: PayloadAction) => action is PayloadAction; } export type ContextStore = S & { error?: ContextStoreError; }; export type ContextStoreActionCallback = (state: S) => S; export type ContextStoreError = unknown | string; export type ContextStoreInitializer = (initialState?: I extends S ? S : I, edit?: boolean) => S; export type ActionCreatorType = { [key: string]: (...args: any[]) => any; }; export type DispatchMaybeWithAction = (value?: A) => void; export type PayloadActionType = { type: T; } & ([M] extends [never] ? {} : { meta: M; }) & ([E] extends [never] ? {} : { error: E; }); export type PayloadAction = { type: T; payload: P; } & ([M] extends [never] ? {} : { meta: M; }) & ([E] extends [never] ? {} : { error: E; }); export type PayloadActionCreator

= { type: T; payload: P; (payload: P): { type: T; payload: P; }; }; export type PrepareAction

= ((...args: any[]) => { payload: P; }) | ((...args: any[]) => { payload: P; meta: any; }) | ((...args: any[]) => { payload: P; error: any; }) | ((...args: any[]) => { payload: P; meta: any; error: any; }); export type ReducerMaybeWithAction = (state: S, action?: A) => S; export type ReducerStateMaybeWithAction, A = DispatchMaybeWithAction> = R extends ReducerMaybeWithAction ? S : never; export type Thunk = (dispatch: Dispatch, getState: () => RefObject['current']) => PayloadActionCreator | Promise

| Promise | P; export type ThunkFunction

= IsAny, IsUnknownOrNonInferrable, IfVoid, IfMaybeUndefined, ThunkFunctionWithParam>>>>; type ThunkFunctionWithParam = (param: Param) => Thunk; type ThunkFunctionWithOptionalPayload = (param?: Param) => Thunk; export type LoosePartial = { [P in keyof T]?: T[P] | undefined; }; export type DataComponent = { data: T[]; }; export type DataConfigComponent = DataComponent & { config: C[]; }; export type Ensure = T & PickEnsure; export type Falsely = null | undefined | false | typeof NaN | 0 | bigint | ''; export type LayoutProps = { Footer?: ComponentType; Header?: ComponentType; children: ReactNode; }; export type Nullable = T | null; export type NumberBoolean = 0 | 1; export type PickEnsure = Required>>; export type PickPartial = Partial>; export type RequiredNotNull = { [P in keyof T]: NonNullable; }; export type Subset = Pick; export type Truthy = T extends Falsely ? never : T; export type ValueComponent = { value: T; }; export type Writeable = { -readonly [P in keyof T]: T[P]; }; export interface ClickableComponent { onClick?: React.MouseEventHandler; } export interface ExtendableComponent extends ClickableComponent { className?: string; style?: CSSProperties; children?: React.ReactNode; } export interface PolyMorphicComponent extends ExtendableComponent { component?: T; props?: React.ComponentProps; } export type Reducer = (state: S, action: A) => S; export type Action = ActionCreatorWithPayload | PayloadActionCreator; export {};