ianI
Convex Community3y ago
2 replies
ian

Want branded strings or more specific

Want branded strings or more specific types?

I just realized this just works:

defineSchema({
  myTable: defineTable({
    myField: v.string() as Validator<MyStringType>
  })
)}

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.
Was this page helpful?