I have written a helper function that allows me to validate FormData objects using Zod. Since this can be used for various schemas, I have used a generic type.
The problem I'm having is, when using the helper function it seems to be turning the properties with default values set in the schemas to optional:
The fact this is being returned with an optional property just doesn't make any sense to me. Any explanation or help would be much appreciated 😊.
Worth noting that if I don't run this through the helper function and parse it directly in the action, it isn't returning as optional which you would expect.
I have written a helper function that allows me to validate FormData objects using Zod. Since this can be used for various schemas, I have used a generic type.
The problem I'm having is, when using the helper function it seems to be turning the properties with default values set in the schemas to optional:
Here is the code for the validate helper function:
The fact this is being returned with an optional property just doesn't make any sense to me. Any explanation or help would be much appreciated 😊.
Worth noting that if I don't run this through the helper function and parse it directly in the action, it isn't returning as optional which you would expect.