Losing custom $types in pg jsonb using drizzle-zod

Not sure if this is an expected limitation of zod here
export const records = pgTable('records', {
    id: uuid('id')
        .primaryKey()
        .$defaultFn(() => uuidv7()),
    tableId: uuid('table_id')
        .references(() => tables.id, { onDelete: 'cascade' })
        .notNull(),
    organizationId: uuid('organization_id')
        .references(() => organizations.id, { onDelete: 'cascade' })
        .notNull(),
    recordByFieldId: jsonb('record_by_field_id').$type<RecordData>(),

})


produces using $inferInsert
type Record = {
    organizationId: string;
    tableId: string;
    id?: string;
    recordByFieldId?: RecordData | null;
    createdAt?: Date;
    updatedAt?: Date | null;
}


But when using drizzle zod, i lose RecordData
export const insertRecordSchema = createInsertSchema(records)
export type InsertRecord = z.infer<typeof insertRecordSchema>

// results in
type InsertRecord = {
    organizationId: string;
    tableId: string;
    id?: string;
    recordByFieldId?: any;
    createdAt?: Date;
    updatedAt?: Date | null;
}
Was this page helpful?