import { KeysDefinition } from '.'; declare type ValueByKeyByTag, Tags extends keyof Union = keyof Union> = { [Tag in Tags]: { [Key in Union[Tag]]: Union extends { [r in Tag]: Key; } ? Union : never; }; }; declare type Cases = { [key in keyof Record]: (v: Record[key]) => R; }; interface Folder { (f: (a: A) => R): (a: A) => R; } interface Default { default: (a: A) => R; } /** * Dispatch calls for each tag value, ensuring a common result type `R` */ interface Matcher extends MatcherInter[Tag]> { } interface MatcherInter { (match: Cases): (a: A) => R; (match: Partial> & Default): (a: A) => R; } interface Transform extends TransformInter[Tag]> { } interface TransformInter { (match: Partial>): (a: A) => A; } interface ReducerBuilder { (match: Cases[Tag], (s: S) => S>): Reducer; (match: Partial[Tag], (s: S) => S>> & Default S>): Reducer; } /** * Same purpose as `Matcher` but the result type is infered as a union of all branches results types */ interface MatcherWiden extends MatcherWidenIntern[Tag]> { } interface MatcherWidenIntern { >(match: M): (a: A) => ReturnType extends infer R ? R : never; > & Default>(match: M): (a: A) => ReturnType> extends infer R ? R : never; } export interface Reducer { (state: S | undefined, action: A): S; } export interface Matchers { fold: Folder; match: Matcher; transform: Transform; matchWiden: MatcherWiden; createReducer: (initialState: S) => ReducerBuilder; } export declare const Matchers: (tag: Tag) => (keys: KeysDefinition) => Matchers; export {};