Handling `null` and `undefined` values in TypeScript, especially when interfacing with databases,...
Hey all,
I'm using
I was working on a way to decode/encode between the stored data and the interface we use to access properties in the code itself;
Long story short -- it seems that the stored booking type seems to have a type of
Looking deeper in the StoredBooking type, we see this:
What's the best way to approach this? I think that
I'm using
drizzle-orm/sqlite-core with drizzle-orm/libsql to interface with Effect code. I made this table:I was working on a way to decode/encode between the stored data and the interface we use to access properties in the code itself;
Long story short -- it seems that the stored booking type seems to have a type of
string | null on requestNote which is an optional field in the sqliteTable. I've read somewhere that Drizzle sets this to null by default instead of being able to return undefined as well. This is causing a discrepancy in the expected types, as Schema defines optional as what is basically T | undefined.Looking deeper in the StoredBooking type, we see this:
What's the best way to approach this? I think that
undefined being the default is something I prefer, and I'd love to know if there's an easy way to handle this from the table itself.