-
Notifications
You must be signed in to change notification settings - Fork 102
Introduce PipeSeparatedFlags<T>
marker class
#2214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
*/ | ||
export type SimpleQueryStringFlags = SimpleQueryStringFlag | string | ||
export type SimpleQueryStringFlags = FlagsEnum<SimpleQueryStringFlag[]> | ||
|
||
export enum SimpleQueryStringFlag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not make a real difference as these values are currently not part of the generated schema, but I adjusted them anyways based on their actual values:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you can remove these constants altogether. They're some ancient leftovers from the very first iterations on the TypeScript spec where integer constants were added to the enums.
FlagsEnum<T>
marker classPipeSeparatedFlags<T>
marker class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. As mentioned in the comment, we can remove the integer constants in the enum.
*/ | ||
export type SimpleQueryStringFlags = SimpleQueryStringFlag | string | ||
export type SimpleQueryStringFlags = FlagsEnum<SimpleQueryStringFlag[]> | ||
|
||
export enum SimpleQueryStringFlag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you can remove these constants altogether. They're some ancient leftovers from the very first iterations on the TypeScript spec where integer constants were added to the enums.
What?
This PR introduces the
FlagsEnum<T>
marker class similar to theStringified<T>
concept.Flags enums are defined as enums with a special case serialization. Values of this enum are represented as
string
(like for regular enums as well). In addition, individual enum member values can be combined using the pipe separator char (|
) like e.g. described here:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html#supported-flags
Why?
At the moment, this specific construct is defined in 2 parts:
TEnum
) as a regular enum typeFlagsEnum = TEnum | string
Using just a generic union makes it hard to generate correct (de-)serialization code and "hard" for the users to use properties of this type, as they have to manually craft strings when using multiple values (unintuitive, error prone, ...).
In case of C#, this marker would allow me to e.g. generate a native language construct:
and allows the user to utilize the standard way of working with flags: