diff --git a/zod/src/__tests__/Form.tsx b/zod/src/__tests__/Form.tsx index 5971c7df..16ee5da5 100644 --- a/zod/src/__tests__/Form.tsx +++ b/zod/src/__tests__/Form.tsx @@ -10,17 +10,22 @@ const schema = z.object({ password: z.string().nonempty({ message: 'password field is required' }), }); -type FormData = z.infer & { unusedProperty: string }; +type SchemaInput = z.input; +type FormData = z.output & { unusedProperty: string }; function TestComponent({ onSubmit, -}: { onSubmit: (data: z.infer) => void }) { +}: { onSubmit: (data: z.output) => void }) { const { register, handleSubmit, formState: { errors }, - } = useForm({ + } = useForm({ resolver: zodResolver(schema), // Useful to check TypeScript regressions + defaultValues: { + username: '', + password: '', + }, }); return ( @@ -58,7 +63,7 @@ export function TestComponentManualType({ register, handleSubmit, formState: { errors }, - } = useForm, undefined, FormData>({ + } = useForm({ resolver: zodResolver(schema), // Useful to check TypeScript regressions }); diff --git a/zod/src/zod.ts b/zod/src/zod.ts index 8ac45412..d811d84d 100644 --- a/zod/src/zod.ts +++ b/zod/src/zod.ts @@ -68,7 +68,7 @@ function parseErrorSchema( * @param {Object} [resolverOptions] - Optional resolver-specific configuration * @param {('async'|'sync')} [resolverOptions.mode='async'] - Validation mode. Use 'sync' for synchronous validation * @param {boolean} [resolverOptions.raw=false] - If true, returns the raw form values instead of the parsed data - * @returns {Resolver>} A resolver function compatible with react-hook-form + * @returns {Resolver>} A resolver function compatible with react-hook-form * @throws {Error} Throws if validation fails with a non-Zod error * @example * const schema = z.object({ @@ -87,7 +87,7 @@ export function zodResolver( mode?: 'async' | 'sync'; raw?: boolean; } = {}, -): Resolver> { +): Resolver> { return async (values, _, options) => { try { const data = await schema[