import {ValidationFailure} from '../error' import {Validator} from '../interface' export class NullableValidator implements Validator { constructor(public readonly value: Validator) {} cast(value: unknown): ValidationFailure | T | null { if (value === null) { return null } else { return this.value.cast(value) } } validate(value: unknown): ValidationFailure | undefined { if (value === null) return return this.value.validate(value) } phantom(): S | null { return null } }