Closed jwatte closed 2 weeks ago
Also, the lazy()
doesn't matter (happens without it,) and trying to tack on .pipe(z.coerce.boolean())
doesn't work, same error.
Looking at this some more, the problem here is that the z.ZodType<Output, Def, Input>
typedef defaults Input
to Output
and in this case, Input
is something else.
So, I have to indirect another type for the z.input<typeof ZInner>
and pass that to the ZodType
definition, and then it works.
In a much bigger project, I have a compile error where it complains that a type "string | boolean" can't be assigned to "boolean." I want to define a boolean field that can coerce from string. Unfortunately, "coerce" doesn't work, because the string "false" is coerced to true, because it's JavaScript truthy. Thus, I tried using transform() instead.
Here is the small reproduction case:
This gives the following error:
It is my assumption that, if
IInner
is boolean-only, thenz.array(ZInner)
should also be. However, this doesn't seem to hold true.