import { Parser } from "."; import { IParser, OnParse } from "./interfaces"; export class OnMismatch> implements IParser { constructor( readonly parent: Parser, readonly defaultValue: (a: A) => B2, readonly description = { name: "OnMismatch" as const, children: [parent], extras: [defaultValue], } as const, ) {} parse(a: A, onParse: OnParse): C | D { const parentCheck = this.parent.enumParsed(a); if ("error" in parentCheck) { return onParse.parsed(this.defaultValue(a) as any as B); } return onParse.parsed(parentCheck.value as any); } } export type DeepReadonly = { readonly [P in keyof T]: DeepReadonly; };