Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 7x 10x 10x | export type ValidationFieldPath<T extends object> =
| "root"
| Extract<keyof T, string>
| `${Extract<keyof T, string>}.${string}`;
export type ValidationFieldErrors<T extends object> = Partial<
Record<ValidationFieldPath<T>, string>
>;
export interface ValidationResult<T extends object> {
isValid: boolean;
fieldErrors: ValidationFieldErrors<T>;
}
export type FormValidator<T extends object> = (data: T) => ValidationResult<T>;
export const validationSuccess = <T extends object>(): ValidationResult<T> => ({
isValid: true,
fieldErrors: {},
});
export const validationFailure = <T extends object>(
fieldErrors: ValidationFieldErrors<T>,
): ValidationResult<T> => ({
isValid: false,
fieldErrors,
});
|