Type Inference Issue: Missing | null on Relational Fields in Drizzle ORM
When querying a company and joining related customer data, the resulting inferred TypeScript type for the customer property does not allow for null even though no record may exist. Because of this, the type inference is overly strict. In many cases, customer can be null, especially with a left join or if the relation is optional.
Expected Behavior:
When using a relational query (e.g. with: { customer: { ... } }), the inferred TypeScript type should include | null (or | undefined) for the customer property if it is optional or if no matching record exists.
Actual Behavior:
The inferred type forces the customer property to always exist, which causes runtime errors in bussines code because of the types mismatch.
1 Reply
https://github.com/drizzle-team/drizzle-orm/issues/3799
I believe this is it.
GitHub
[BUG]: Incorrect Non-Nullable Type Inference for One-to-One Related...
Report hasn't been filed before. I have verified that the bug I'm about to report hasn't been filed before. What version of drizzle-orm are you using? 0.38.2 What version of drizzle-kit...