Schema Intersection
I try to create the following model:
I've read about unions at the top level here: https://docs.convex.dev/database/schemas#unions
However, as you can see, I need the status field that is true for all asset types. I tried to do this:
For now, I can't understand how to implement the aforementioned type. Seems like it lacks
v.intersection()
API.Schemas | Convex Developer Hub
Schema validation keeps your Convex data neat and tidy. It also gives you end-to-end TypeScript type safety!
5 Replies
Also, I wouldn't like to create a nested object since I have to index by type
Simple:
Fancy:
Fanciest:
Thought exactly the same thing. Thanks!
Also thought about the following:
Doable but harder to type annotate
Maybe @ian could build this into
convex-helpers
, I can see this being a fairly general pattern.Also, I wouldn't like to create a nested object since I have to index by typeIf you're talking about Convex indexes, you can define indexes on nested properties!