Using with NestJS and Zod
I'm trying to use
drizzle-zod
and nestjs-zod
together to create Zod schemas and classes for insert and select. I mostly got it to work, even with Swagger! However, I'm running into a problem with one of the create schemas. My table is defined:
Then I create the Zod schema for inserting
And then I turn that into a class
However, when I try to do something like
I get Property 'firstLine' is optional in type 'NewAddress' but required in type '{ firstLine: string | SQL<unknown> | Placeholder<string, any>;...
. Looking at the generated class, every property has ?
after it, and I'm not sure if that's a drizzle-zod
problem or a nestjs-zod
problem.
Any information would be awesome, thanks! So far I'm loving using Drizzle1 Reply
It seems the issue comes from the default tsconfig.ts of Nestjs.
Even normal Zod has this issue on Nestjs.
strictNullChecks=false makes z.object() properties optional
From the documentation of Zod, the strict mode must be enabled for Zod to work properly and strictNullChecks is part of the strict mode so needs to enable too
you should modify your tsconfig.ts to have this
{
"compilerOptions": {
"strictNullChecks": true,
"strict": true,
}
}