Struggling to use Zod with Drizzle... Type errors around |undefined
I'm attemping to perform validation and inserting with Zod... however, I'm getting errors around the fact the generated schema includes |undefined in each of the rows... Is there a way around this? Sorry for the noob question.
4 Replies
for added context:
this appears to be an issue with Zod itself, what a bummer
Dunno, I tried your schema and it works just fine.
gives me no TS errors.
The only way I can get the same TS error as you is if somehow
parsedRequest
has unknown type ... e.g.
I don't know how that would happen, unless VSCode is confused, in which case I would restart the TS language server (or just VSCode)
The error says Argument of type 'unknown' is not assignable to parameter of type '{ name ...
, so somehow TS thinks that your parsedRequest
variable has type unknown
In your TS config, do you have
exactOptionalPropertyTypes
enabled? This is the flag that causes the issue
By default, Zod includes | undefined on fields with Zod.Optional(), this causes an issue since there’s a difference between a type that is set to undefined and getting ‘undefined’ from a variable, which is what that flag enforces checks for.
I’ve since switched to Drizzle Typebox which is quite a bit less headache and had this flag in mind from the get go :)Ah I see ... I don't have that flag