Unions of literals / Enums
Has there been any consideration to supporting enums in the schema data types? I'm referring to enum in a very loose sense here -- basically type safety that a field will have a particular value.
Eg:
Then when utilizing I will not be able to specify a value for
table.field
that isn't "this" or "that", and when i get
a table doc, I'll have table.field
will have a type of MySupportedValues
.4 Replies
Does this help? https://docs.convex.dev/using/schemas#literals
Defining a Schema | Convex Developer Hub
End-to-end type safety requires typing your tables.
union of
s.literal
might do the trick(Also check out https://docs.convex.dev/using/schemas#infertypeof-schemavalue for a way to get
MySupportedValues
from a s.union(s.literal(...), ...)
definition)Defining a Schema | Convex Developer Hub
End-to-end type safety requires typing your tables.
Thanks, Jamie. I'll take a look at this.
I was looking at https://docs.convex.dev/using/types
Types | Convex Developer Hub
All Convex documents are defined as Javascript objects. These objects can have