Skip to content
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

string enums: Infer default value from key #36319

Closed
KennethKo opened this issue Jan 20, 2020 · 1 comment
Closed

string enums: Infer default value from key #36319

KennethKo opened this issue Jan 20, 2020 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@KennethKo
Copy link

Search Terms

string enum
default value
initializer
infer

Suggestion

Add syntactic sugar to string enum declarations to infer their values from their key names. The overwhelming majority of string enum values are identical or near-identical to their key names, and it's kludgy to list every reserved value twice in its declaration.

enum<string> Foo {
  A,
  B,
  ...,
  Y = 'LegacyOverrideYValue',
  Z,
  LongAndSimilarEnumName,
  LongUnsimilarEnumName,
}

// instead of 

enum Foo {
  A = 'A',
  B = 'B',
  ...,
  Y = 'LegacyOverrideYValue',
  Z = 'Z',
  LongAndSimilarEnumName = 'LongAndSimilarEnumName',
  LongUnsimilarEnumName = 'LongUnSimilarEnumName',
}
// which contains a sneaky bug
@AnyhowStep
Copy link
Contributor

#16464

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants