Using with NestJS and Zod

NNoahh5/9/2023
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:

export const addresses = pgTable('addresses', {
  id: uuid('id').defaultRandom().primaryKey(),
  name: text('name'),
  placeId: text('place_id'),
  firstLine: text('first_line').notNull(),
  secondLine: text('second_line'),
  city: text('city').notNull(),
  state: text('state').notNull(),
  zipCode: text('zip_code').notNull(),
  country: text('country').notNull(),
  latitude: decimal('latitude', {
    precision: 8,
    scale: 6,
  }).notNull(),
  longitude: decimal('longitude', {
    precision: 9,
    scale: 6,
  }).notNull(),
  instructions: text('instructions'),
  createdAt: timestamp('created_at').defaultNow(),
});


Then I create the Zod schema for inserting
const createAddressSchema = createInsertSchema(addresses);


And then I turn that into a class
import { createZodDto } from 'nestjs-zod';

export class NewAddress extends createZodDto(createAddressSchema) {}


However, when I try to do something like
const address = await context
        .insert(addresses)
        .values({} as NewAddress) // Not actually what I'm doing, just doing it to get the error
        .returning({ id: addresses.id });


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 Drizzle