Custom "enum" types with a custom type provider #1068
-
In our language context we have dynamic enum-like types. For example, a query might be:
The enum type I'm unsure exactly how to define this with the custom type provider. I've achieved a working solution by defining the enum type as a constant object type and its values as opaque types. Could this be considered a reasonable approach? We define all our types dynamically at runtime (and not using Go structs or proto definitions). The below Gist very simply illustrates how I have achieved this: https://gist.github.com/davenewza/81ebf3f30b0fde94419d9ba090327a5c What isn't so great about this approach is:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@TristonianJones - would you be able to help me with this? |
Beta Was this translation helpful? Give feedback.
-
Hi @davenewza, Here are a few tips in no specific order:
Since The error message for comparing two unequal types is probably about as clear as we can get since we don't have a sense of intent during type-checking. -Tristan |
Beta Was this translation helpful? Give feedback.
Hi @davenewza,
Here are a few tips in no specific order:
cel.Constant
call should provide a value associated with the variable and type information.operator.Equals
isT == T
, so you don't really need to create a custom overloadcel.OpaqueType
for a type that has no accessible fields, andcel.ObjectType
for a type with accessible fields.types.NewNullableType()
sincenull
should really only be used for JSON values and in some limited circumstances for well-known protobuf types.Since
Status
is anObjectType
, the error messages will be based upon a typed field-access. We can certainly update the error message to indic…