export interface Const { readonly _const: T; } export interface Generic { opaque: 'Generic is a token type that is going to be replaced with a real type'; } export interface Unit { opaque: 'opaque token for empty payload type'; } export declare type Case = Of | Const; export interface RecordDict { readonly [key: string]: Case; } export declare type SingleDataCase = Of<[Unit]> | Const | Of<[unknown]>; export interface SingleDataRecordDict { readonly [key: string]: SingleDataCase; } export interface ForbidDefault { default?: never; } export declare type ForbidReservedProps = { readonly if?: never; readonly match?: never; readonly matchWith?: never; readonly T?: never; } & ForbidDefault; export declare type RequiredRecordType = RecordDict & ForbidReservedProps; export declare type SingleDataRecordType = SingleDataRecordDict & ForbidReservedProps; export interface Of { _opaque: T; } export interface Types { (unit: null): Of<[Unit]>; (): Of<[T]>; (g: Generic): Of<[Generic]>; (val: T): Const; (): Of<[T1, T2]>; (): Of<[T1, T2, T3]>; } export declare const of: Types; export interface UnionVal { readonly _opaqueToken: Record; } export interface UnionValG { readonly _opaqueToken: Record; readonly _type: P; } export declare type GenericValType = Val extends UnionValG ? UnionValG : never; export declare type Constructors = { [T in keyof Record]: CreatorFunc>; }; export declare type ConstructorsG = { [K in keyof Record]: CreatorFuncG; }; export declare type Cases = { [T in keyof Record]: MatchCaseFunc; }; export declare type CasesG = { [K in keyof Record]: MatchCaseFuncG; }; export declare type CreatorFunc = K extends Of ? A extends [void] ? () => UVal : A extends [Unit] ? UVal : A extends any[] ? (...p: A) => UVal : never : K extends Const ? () => UVal : never; export declare type CreatorFuncG = K extends Of ? A extends [void] ?

() => UnionValG : A extends [Unit] ?

() => UnionValG : A extends [Generic] ?

(val: P) => UnionValG : A extends any[] ?

(...p: A) => UnionValG : never : K extends Const ?

() => UnionValG : never; export declare type MatchCaseFunc = K extends Of ? A extends [void] ? () => Res : A extends [Unit] ? () => Res : A extends any[] ? (...p: A) => Res : never : K extends Const ? (c: C) => Res : never; export declare type MatchCaseFuncG = K extends Of ? A extends [void] ? () => Res : A extends [Unit] ? () => Res : A extends [Generic] ? (val: P) => Res : A extends any[] ? (...p: A) => Res : never : K extends Const ? (c: C) => Res : never; export declare type MatchCases = (Cases & ForbidDefault) | (Partial> & { default: (val: UnionVal) => Result; }); export declare type MatchCasesG = (CasesG & ForbidDefault) | (Partial> & { default: (val: UnionValG) => Result; }); export interface MatchFunc { (cases: MatchCases): (val: UnionVal) => Result; (val: UnionVal, cases: MatchCases): Result; } export interface MatchFuncG { (cases: MatchCasesG): (val: UnionValG) => Result; (val: UnionValG, cases: MatchCasesG): Result; } export declare type UnpackFunc = K extends Of ? A extends [void] ? { (val: UnionVal, f: () => R): R | undefined; (val: UnionVal, f: () => R, els: (v: UnionVal) => R): R; } : A extends [Unit] ? { (val: UnionVal, f: () => R): R | undefined; (val: UnionVal, f: () => R, els: (v: UnionVal) => R): R; } : A extends any[] ? { (val: UnionVal, f: (...p: A) => R): R | undefined; (val: UnionVal, f: (...p: A) => R, els: (v: UnionVal) => R): R; } : never : K extends Const ? { (val: UnionVal, f: (с: С) => R): R | undefined; (val: UnionVal, f: (с: С) => R, els: (v: UnionVal) => R): R; } : never; export declare type UnpackFuncG = K extends Of ? A extends [void] ? { (val: UnionValG, f: () => R): R | undefined; (val: UnionValG, f: () => R, els: (v: UnionValG) => R): R; } : A extends [Unit] ? { (val: UnionValG, f: () => R): R | undefined; (val: UnionValG, f: () => R, els: (v: UnionValG) => R): R; } : A extends [Generic] ? { (val: UnionValG, f: (val: P) => R): R | undefined; (val: UnionValG, f: (val: P) => R, els: (v: UnionValG) => R): R; } : A extends any[] ? { (val: UnionValG, f: (...p: A) => R): R | undefined; (val: UnionValG, f: (...p: A) => R, els: (v: UnionValG) => R): R; } : never : K extends Const ? { (val: UnionValG, f: (с: С) => R): R | undefined; (val: UnionValG, f: (с: С) => R, els: (v: UnionValG) => R): R; } : never; export declare type Unpack = { [K in keyof Rec]: UnpackFunc; }; export declare type UnpackG = { [K in keyof Rec]: UnpackFuncG; }; declare type UnionDesc = { if: Unpack; T: UnionVal; match: MatchFunc; matchWith: Rec extends SingleDataRecordType ? (other: UnionDesc, matchObj: MatchCasesForTwo) => (a: UnionVal, b: UnionVal) => Result : never; } & Constructors; export declare type UnionObj = UnionDesc; export declare type GenericUnionDesc = { match: MatchFuncG; if: UnpackG; T: UnionValG; } & ConstructorsG; declare type TypeOfLeg = Leg extends Of ? A extends [void] | [Unit] ? void : A extends [infer Value] ? Value : A extends Const ? C : never : never; export declare type MatchCaseFuncTwo = (a: TypeOfLeg, b: TypeOfLeg) => Res; export declare type CasesTwo = { [KA in keyof RecordA]?: { [KB in keyof RecordB]?: MatchCaseFuncTwo; }; }; export declare type MatchCasesForTwo = CasesTwo & { default: (a: UnionVal, b: UnionVal) => Result; }; export interface UnionFunc { (record: R): UnionDesc; (ctor: (g: Generic) => R): GenericUnionDesc; } export declare const Union: UnionFunc; export {};