resolvers icon indicating copy to clipboard operation
resolvers copied to clipboard

issue: [zod] Using enum values as keys of an object causes a type error when trying to watch the value

Open jcohen14 opened this issue 7 months ago • 0 comments

Version Number

5.0.1 (zod v3.24.2, RHF v7.55.0)

Codesandbox/Expo snack

https://codesandbox.io/p/sandbox/mxfzvx

Steps to reproduce

  1. Create a fresh react project with zod, RHF, and @hookform/resolvers
  2. create a zod schema that has an object keyed by an enum (not a Record)
  3. set up a component that provides a useForm return via FormProvider, passing the zod schema to useForm with the zodResolver
  4. create a consumer component that calls useFormContext to get access to watch
  5. try to watch one of the fields keyed by an enum
  6. it will yield a type error

I'm not even sure if this is the right place to report this issue, so apologies if that is the case.

Expected behaviour

watch should not throw a type error, and should correctly infer the type of the array from the schema/zod type.

What browsers are you seeing the problem on?

Chrome

Relevant log output

N/A

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

jcohen14 avatar Apr 09 '25 22:04 jcohen14