TanStackT
TanStack9mo ago
7 replies
ordinary-sapphire

TypeScript issue if the (zod) schema is a union or is using superRefine?

Hi,

I created a minimal reproducible example of a ecommerce form I am working on: https://github.com/thobas-dnvgl/tanstack-demo

The ieda is to ask for the mailing address and have a choice (off by default) to enter another address for the billing address.

I thought about using a discriminated union but I get a TypeScript error. I then used .superRefine but I still get a TypeScript error (all of that is documented in the README in the repository). The form works as expected and the error disappears if I do not use satisfies TypeData on the defautlValues but it's less type safe.

Any idea what's going on? Bug in TanStrack Form? Zod schema that could be improved?

Thanks!
GitHub
TanStack Form demo with zod and radio buttons (yes the name of the repo could have been better) - thobas-dnvgl/tanstack-demo
GitHub - thobas-dnvgl/tanstack-demo: TanStack Form demo with zod an...
Was this page helpful?