Open samislam opened 11 months ago
Instead of using z.date()
try using z.coerce.date()
. While you may receive a string, Zod will try coerce it into a Date before performing validation. I haven't tested this against your exact use case but I do remember this working in the past for a similar issue.
Using .coerce results in error in console + schema validation fail: The specified value "Sat Jan 01 2000 01:00:00 GMT+0100 (Central European Standard Time)" does not conform to the required format, "yyyy-MM-dd"
If you use a date type in your zod schema as follows it will always fail validation, because JSON does not have date type, only strings, and zod will always think that string is not of type date, and thus, validation fails:
Are there any plans to solve this problem?
Codesandbox here