UNPKG

mobx-state-tree

Version:

Opinionated, transactional, MobX powered state container

34 lines (33 loc) 1.54 kB
import { IType, IAnyType, _NotCustomized } from "../../internal"; export type ITypeDispatcher<Types extends IAnyType[]> = (snapshot: Types[number]["SnapshotType"]) => Types[number]; export interface UnionOptions<Types extends IAnyType[]> { /** * Whether or not to use eager validation. * * When `true`, the first matching type will be used. Otherwise, all types will be checked and the * validation will pass if and only if a single type matches. */ eager?: boolean; /** * A function that returns the type to be used given an input snapshot. */ dispatcher?: ITypeDispatcher<Types>; } /** * Transform _NotCustomized | _NotCustomized... to _NotCustomized, _NotCustomized | A | B to A | B * @hidden */ export type _CustomCSProcessor<T> = Exclude<T, _NotCustomized> extends never ? _NotCustomized : Exclude<T, _NotCustomized>; /** @hidden */ export interface ITypeUnion<C, S, T> extends IType<_CustomCSProcessor<C>, _CustomCSProcessor<S>, T> { } export type IUnionType<Types extends IAnyType[]> = ITypeUnion<Types[number]["CreationType"], Types[number]["SnapshotType"], Types[number]["TypeWithoutSTN"]>; export declare function union<Types extends IAnyType[]>(...types: Types): IUnionType<Types>; export declare function union<Types extends IAnyType[]>(options: UnionOptions<Types>, ...types: Types): IUnionType<Types>; /** * Returns if a given value represents a union type. * * @param type * @returns */ export declare function isUnionType(type: unknown): type is IUnionType<IAnyType[]>;