updux/src/types.ts

26 lines
601 B
TypeScript

/**
* Configuration object typically passed to the constructor of the class Updux.
*/
export interface UpduxConfig<TState = any, TSubduxes = {}> {
/**
* Local initial state.
* @default {}
*/
initial?: TState;
/**
* Subduxes to be merged to this dux.
*/
subduxes?: TSubduxes;
}
type StateOf<D> = D extends { initial: infer I } ? I : unknown;
export type DuxStateSubduxes<C extends {}> = keyof C extends never
? unknown
: { [K in keyof C]: StateOf<C[K]> };
export type DuxAggregateState<TState,TSubduxes> = TState & DuxStateSubduxes<TSubduxes> ;