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
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;
}
type TestTypeWrong = {
id?: string;
optional?: string;
notOptional?: string;
unique?: string;
}
type TestTypeCorrect = {
id: string;
notOptional: string;
unique: string;
optional?: string;
}
1 Reply
ManuRodgers
ManuRodgers13mo ago
I have the same issue here
Want results from more Discord servers?
Add your server