Want branded strings or more specific
Want branded strings or more specific types?
I just realized this just works:
myField
will be typed as MyStringType
when you get it from the DB, and give you errors on functions like withIndex
if your parameter isn't MyStringType
when comparing against myField
Note: this isn't runtime validation, this is just type annotations to help you catch bugs & be more descriptive.3 Replies
This looks super cool! Can you elaborate on what
MyStringType
could look like?export type MyStringType = string & { __myStringType: never };
Better yet, here's a little article on it I just wrote for you: https://stack.convex.dev/using-branded-types-in-validatorsUsing branded types in validators
If you have a more specific type than what you can express with Convex validators, you can still document that at the type level in Convex by casting ...
Can chat about it here: https://discord.com/channels/1019350475847499849/1198117197638291546