@conform-to/zod
Version:
Conform helpers for integrating with Zod
65 lines • 2.36 kB
TypeScript
import { configureCoercion as baseConfigureCoercion } from './coercion';
/**
* @deprecated Use `getConstraints` instead.
*/
export { getZodConstraint } from './constraint';
export { formatResult } from './format';
export { isSchema, getConstraints } from './schema';
export declare function configureCoercion(config?: Parameters<typeof baseConfigureCoercion>[0]): ReturnType<typeof baseConfigureCoercion>;
/**
* Enhances a schema to coerce form values and strip empty values before validation.
* Use `configureCoercion` to override empty-string handling and type-specific coercion.
*
* Results are cached per schema, so this can be called inline.
*
* **Example:**
*
* ```tsx
* import { coerceFormValue } from '@conform-to/zod/v3/future';
* import { z } from 'zod';
*
* const schema = coerceFormValue(z.object({
* age: z.number().optional(),
* subscribe: z.boolean(),
* }));
*
* schema.parse({ age: '', subscribe: 'on' });
* // { age: undefined, subscribe: true }
* ```
*/
export declare const coerceFormValue: <Schema extends import("zod").ZodTypeAny>(type: Schema) => import("zod").ZodType<import("zod").output<Schema>, import("zod").ZodTypeDef, import("zod").input<Schema>>;
/**
* Enhances a schema to coerce form values without running validation.
* This is useful for reading current form values as typed data.
*
* It skips validation, defaults, transforms, and refinements, and does not strip
* empty strings to `undefined`.
*
* For number, boolean, date, and bigint schemas, empty strings and other failed
* string coercions still become fallback values:
*
* - `z.number()` -> `NaN`
* - `z.boolean()` -> `false`
* - `z.date()` -> `Invalid Date`
* - `z.bigint()` -> `0n`
*
* Use `configureCoercion` to override type-specific coercion.
*
* Results are cached per schema, so this can be called inline.
*
* **Example:**
*
* ```tsx
* import { coerceStructure } from '@conform-to/zod/v3/future';
* import { z } from 'zod';
*
* const schema = coerceStructure(z.object({
* age: z.number().min(10),
* }));
*
* schema.parse({ age: '3' });
* // { age: 3 }
* ```
*/
export declare const coerceStructure: <Schema extends import("zod").ZodTypeAny>(type: Schema) => import("zod").ZodType<import("zod").input<Schema>, import("zod").ZodTypeDef, import("zod").input<Schema>>;
//# sourceMappingURL=future.d.ts.map