notNull() is still letting field be optional
I am performing the following for SQLite:
However, when I perform:
export type NewProduct = typeof products.$inferInsert;
It says that id
is optional (this is what it shows when i hover over NewProduct
)
How can I fix this?4 Replies
The problem seems to be that
hasDefault
is set to true
; how can I force this to be false
?![No description](https://cdn.answeroverflow.com/1157516480246710332/image.png)
To fix this, I have to do
export type NewProduct = Omit<typeof products.$inferInsert, "id"> & { id: number };
But there should be a way to avoid this, no?
Well this only solves the NewProduct
but doesn't fix the insertProductSchema
since that uses zodThis is intended behavior
$inferInsert
is the type you would need to satisfy if you were inserting a row. Due to ID having a default, you can insert a row without providing an ID, hence number | undefined
What you are looking for is $inferSelect