import {ValidationFailure} from '../error' import {Validator} from '../interface' export class RefValidator implements Validator { private validator?: Validator constructor(private getter: () => Validator) {} getValidator(): Validator { if (this.validator == null) { this.validator = this.getter() } return this.validator } cast(value: unknown): ValidationFailure | T { return this.getValidator().cast(value) } validate(value: unknown): ValidationFailure | undefined { return this.getValidator().validate(value) } phantom(): S { throw new Error() } }