@conform-to/zod
Version:
Conform helpers for integrating with Zod
33 lines • 1.34 kB
TypeScript
import type { SafeParseReturnType, ZodIssue } from 'zod';
import type { FormError } from '@conform-to/dom/future';
/**
* Transforms Zod validation results into Conform's error format.
*
* **Example:**
* ```ts
* const result = schema.safeParse(formData);
* const error = formatResult(result);
* ```
*/
export declare function formatResult(result: SafeParseReturnType<any, any>): FormError<string[]> | null;
export declare function formatResult<Output, ErrorShape>(result: SafeParseReturnType<any, Output>, options: {
/** Whether to include the parsed value in the returned object */
includeValue: true;
/** Custom function to format validation issues for each field */
formatIssues: (issue: ZodIssue[], name: string) => ErrorShape;
}): {
error: FormError<ErrorShape> | null;
value: Output | undefined;
};
export declare function formatResult<Output>(result: SafeParseReturnType<any, Output>, options: {
includeValue: true;
formatIssues?: undefined;
}): {
error: FormError<string[]> | null;
value: Output | undefined;
};
export declare function formatResult<Output, ErrorShape>(result: SafeParseReturnType<any, Output>, options: {
includeValue?: false;
formatIssues: (issue: ZodIssue[], name: string) => ErrorShape;
}): FormError<ErrorShape> | null;
//# sourceMappingURL=format.d.ts.map