import { type ValidationInfo, type Validator } from './validator'; interface FieldProps { value?: V; isDirty?: boolean; } export const withValidator = = FieldProps>( props: P, validator: Validator, ): P & { errors?: ValidationInfo; error?: ValidationInfo[0] } => { const { value, isDirty } = props; const errors: ValidationInfo = isDirty ? validator(value) : []; return { ...props, errors, error: errors[0], }; };