-
Notifications
You must be signed in to change notification settings - Fork 176
Description
Hello 👋
I'm building some small app with tanstack db and one things that bugs me is working with discriminated unions inside of collections. The app is AI chat, so for example I have MessagePart shape, which can be TextMessagePart, ReasoningMessagePart etc. Unfortunately, it's not properly narrowed in many places when using it.
I made a small reproduction, where you can see these issues, that's much easier then to describe it:
As an example I chosen a schema where discriminator is also TKey to showcase also the 2. issue, but it also doesn't work in cases where it's just one of the fields. In my app I have shape with 3 fields basically id, type, data and data is different based on type, I can't properly query this without typecasting/asserting atm
But for completeness:
- Can't discriminate union in either
.whereor.fn.where. It always result in the full model - Collection
TKeyis only inferred properly for few collection types, doesn't work e.g. with local storage or electric ones. They don't pass necessary generics getandupdatein cases whereTKeyis discriminator doesn't properly discriminate