TanStackT
TanStack8mo ago
3 replies
skinny-azure

Zod optional value in schema complains with default value

Hey team, I'm running into an issue where if my zod schema has an optional value in it, and I set that defaultValue then I get a type error. I don't have a reproduction, but if you go to https://tanstack.com/form/latest/docs/framework/react/examples/standard-schema?panel=sandbox and change a value to optional you can see the type error in the sandbox (I've included screen shots). I would have thought that a zod schema that is optional string should allow a default of string and not complain that it could be undefined. I might be missing something though, and I don't want to cast the default values with an as if I can help it...
Screenshot_2025-06-03_at_4.24.30_PM.png
Screenshot_2025-06-03_at_4.25.08_PM.png
Was this page helpful?