Open
Description
String Enum Initializer
A more typesafe and succinct way of defining enum types that compile to strings
Search Terms
enum, string, string enum
default value
initializer
infer
Proposal
It seems like you should be able to specify that you are using a string enum, and then you'd only have to write out the 'value' once, and it would be automatically made into a string matching the enum code.
enum<string> Action {
LOAD_PROFILE,
ADD_TASK,
REMOVE_TASK
}
or
enum Action: string {
LOAD_PROFILE,
ADD_TASK,
REMOVE_TASK
}
instead of
enum Action {
LOAD_PROFILE = "LOAD_PROFILE",
ADD_TASK = "ADD_TASK",
REMOVE_TASK = "REMOVE_TASK"
}
Thanks for all the great work!
EDIT
Recently updated to reflect variations proposed by @imcotton here and @lostpebble here; as well as search terms proposed by @KennethKo (#36319) and @garrettmaring (#33015)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment