react-hook-form / resolvers

📋 Validation resolvers: Yup, Zod, Superstruct, Joi, Vest, Class Validator, io-ts, Nope, computed-types, typanion, Ajv, TypeBox, ArkType, Valibot, effect-ts and VineJS
https://react-hook-form.com/
MIT License
1.72k stars 157 forks source link

Inferring form keys and types from the zod return type #551

Open SeanCassiere opened 1 year ago

SeanCassiere commented 1 year ago

Is your feature request related to a problem? Please describe. It gets pretty annoying when using the zodResolver, that I need to infer the zod-schema type AND pass it into the useForm hook to get the necessary type-completions. It's more frustrating as zod is known for its great TS-first approach and type inference (see the usage in tRPC). This particular gap in the types is noticeable when using the handleSubmit in rhf, and all the key-values are possibly undefined, even though the zod-schema wouldn't allow for it to pass its validation.

Describe the solution you'd like Using the provided zod-schema in the zodResolver to infer the TFieldValues used in the useForm hook in rhf.

Describe alternatives you've considered Generics seem the only feasible way of doing this.

Additional context Add any other context or screenshots about the feature request here.

ctjhoa commented 1 year ago

It was previously request https://github.com/react-hook-form/resolvers/issues/429 and seems intended behavior.