Closed lambertkevin closed 6 months ago
I am facing this issue as well as I need to extend the User zodobject to include an additional password2 field for validation but cant since the extend is not available. Hopefully this can be fixed soon!
Hey @lambertkevin, @ashe0047, as stated in the docs under known issues and limitations:
The satisfies operator: As some people have pointed out the input and output schemas and some of the relation schemas are typed as z.ZodType
. This is required by zod for recursice types to work properly as stated in the docs. This has the downside that some zod methods like .merge(), .omit(), etc. are not available on these types.
It would work for schemas that do not have relations but in my experience even the most simple database schemas have relations and this is where recursive types/schemas come into play.
for extending zodSchemas I'd suggest you use the generated modelSchemas. They do not have a z.ZodType annotation and therefore have all the object methods. It may be a bit more work to make them fit your needs but with the output of options like createOptionalDefaultValuesTypes, createRelationValuesTypes, createPartialTypes you can taylor your own custom schemas.
Thanks for the answer @chrishoermann ! Sorry for missing that part in the doc, my google skills are not that good anymore 😞
Describe the bug Due to the type explicitly added to each schema as
ZodType
, it's impossible to use methods attached to aZodObject
likeextends
,merge
which prevents extending those schemas, orstrip
andpassthrough
which prevents override thestrict
method hardcoded to those schemas.Screenshots
The solution proposed by multiple zod github issues:
Package versions (please complete the following information):
Additional context
satisfies
is only available since TS 4.9 while zod requires 4.5+