@mocanvas/editor · class
declare class UnionValidator<Key extends string, Config extends Record<string, Validatable<object>>, UnknownValue = never> extends Validator<TypeOf<Config[keyof Config]> | UnknownValue>A discriminated union, dispatched on one property.
The interesting part is UnionValidator.validateUnknownVariants: a document may legitimately contain a shape type this build has never heard of — one an app registered in a newer version, or one whose util was not passed to this editor. Rejecting it would delete the user's data on the next save. With unknown variants allowed, the record passes through untouched instead.
Methods · 2
constructor(key: Key, config: Config, unknownValueValidation: ((value: object, variant: string) => UnknownValue) | undefined)validateUnknownVariants<Unknown>(unknownValueValidation: (value: object, variant: string) => Unknown): UnionValidator<Key, Config, Unknown>The same union, but a variant the config does not name is handed to
unknownValueValidation instead of being rejected.
Pass the identity to keep unknown records verbatim, which is what a store that must not lose data wants.
mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.