UNPKG

variant

Version:

Variant types (a.k.a. Discriminated Unions) in TypeScript

14 lines 765 B
import { Handler } from './match'; import { Property, VariantModule, VariantOf } from './variant'; declare type IsFunctions<T extends VariantModule<K>, K extends string = 'type'> = { [P in keyof T]: <O extends Property<K, string>>(object: O | {} | null | undefined) => object is VariantOf<T, P, K>; }; export interface Remote<T extends VariantModule<K>, K extends string = 'type'> { readonly key: K; readonly is: IsFunctions<T, K>; readonly new: T; readonly match: <H extends Handler<T>>(obj: VariantOf<T, undefined, K>, handler: H) => ReturnType<H[keyof H]>; } export declare function remote<T extends VariantModule<K>, K extends string = 'type'>(vmod: T, keyProp?: K): Remote<T, K>; export {}; //# sourceMappingURL=remote.d.ts.map