@jay-js/system
Version:
A powerful and flexible TypeScript library for UI, state management, lazy loading, routing and managing draggable elements in modern web applications.
20 lines (19 loc) • 1.04 kB
TypeScript
import type { ZodSchema } from "../types/external-types.js";
import type { TResolver } from "../types.js";
/**
* Creates a resolver function for validating form values using a Zod schema.
* The type of form values is automatically inferred from the schema.
*
* @template TSchema - The Zod schema type.
* @param {TSchema} schema - The Zod schema to validate the form values against.
* @returns {TResolver<T>} A resolver function that validates the form values and returns validation errors, if any.
*
* The resolver supports validating either the entire form or a single field:
* - If `fieldName` is provided, only the specified field is validated.
* - If `fieldName` is not provided, the entire form is validated.
*
* The returned resolver function:
* - Accepts the form values and an optional field name.
* - Returns an object containing an array of validation errors, or an empty array if validation passes.
*/
export declare function zodResolver<TSchema extends ZodSchema>(schema: TSchema): TResolver<TSchema["_output"]>;