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>(),

})
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;
}
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;
}
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;
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server