Closed pcolmer closed 5 months ago
z.string().date()
was added in Zod 3.23, which is not released yet.
z.string().date() was added in Zod 3.23, which is not released yet.
OK - thank you.
In the absence of having Zod 3.23, is there a solution to getting a custom error message returned? I don't think users contributing to the data in my repo will find it easy to understand date_tested: Expected type "date", received "string"
which is why I wanted to explain that the string needs to be in the specific format YYYY-MM-DD.
Unfortunately, I don't think it's possible to change that error message because it informs that the value found is of the wrong type.
I believe YYYY-MM-DD is the YAML date format, not a string. It's not that a "string" is in the wrong format, but rather that a date format is expected.
So, I will close this issue as I don't think there is anything actionable for docs here, and maybe you can use your contributing guide to provide/highlight the YAML date spec to your contributors to help them with the date format?
๐ Issue Description
The documentation states:
Zod's README gives the following as an example:
However, in Astro,
z.string().date()
is not valid - it has to bez.date()
. Furthermore, it is not possible to usemessage
. It looks like I can useinvalid_type_error
instead, e.g.:but when I try to build a site that might have
date_tested
defined as, sayI get the error
date_tested: Expected type
"date", received "string"
instead of my custom error.๐ On which page(s) it occurs
https://docs.astro.build/en/guides/content-collections/
๐ค Expected Behavior
The documentation needs to make clear that Zod's README is not authoritative and make it clear, for example, that
z.string().date()
is not supported and to usez.date()
instead. I do realise that the existing documentation gives an example ofz.date()
(which is how I figured it out) but it needs to be clearer because of the "supports all of the features of Zod" statement.Furthermore, the issue about the custom error message needs to be cleared up in the documentation if it isn't supported.
๐ Current Behavior
See issue description.
๐ฅ๏ธ Browser
Edge (Chromium version)
๐ Additional Information
No response