How to type an optional included relation?
I'd like to implement a function that given an email returns a user.
The function also gets an optional
includeContacts
boolean. When true
, all user contacts should be returned as well.
Here is what I currently have:
The problem is that user contacts
are not included in the returned type.
Ideally, contacts
will be a non-optional field in the returned type when includeContacts
is true.
Is this possible to achieve?
Here is my schema:
1 Reply
Not within the same query. As you said, the types get messed up. I've been pushing for them to add support for
limit 0
for this reason
https://github.com/drizzle-team/drizzle-orm/pull/2255
It would allow a one-to-many or many-to-many relationship to be made optional via limit
(doesn't break types), rather than an optional with
(breaks types). You can see my current workaround in my Mar 20 comment here.
https://github.com/drizzle-team/drizzle-orm/issues/2011