createInsertSchema does not infer notNull() correclty?

"drizzle-orm": "^0.28.6",
"drizzle-zod": "^0.5.1",

export const testTable = pgTable('accounts', {
    id: varchar('id').primaryKey(),
    optional: varchar('optional'),
    notOptional: varchar('not_optional').notNull(),
    unique: varchar('unique').unique().notNull(),
})

const testSchema = createInsertSchema(testTable)
type TestTypeWrong = z.infer<typeof testSchema>
type TestTypeCorrect = typeof testTable.$inferInsert

Results

type TestTypeWrong = {
    id?: string;
    optional?: string;
    notOptional?: string;
    unique?: string;
}
type TestTypeCorrect = {
    id: string;
    notOptional: string;
    unique: string;
    optional?: string;
}
Was this page helpful?