Make Enums keys a PascalCase by default
See original GitHub issueIf you take a look at typescript docs, you can see that Enums are PascalCase. But here when you have enum generated, they are taken as is from the schema. What do you think to generate left side as PascalCase while right side to be the actual value from the schema enum definition?
We have a huge codebase and many enums are already PascalCase having them mixed is rather a pain in the ass.
Schema:
enum SomeEnum {
COOL
NOT_COOL
}
Current:
enum SomeEnum {
COOL = "COOL",
NOT_COOL = "NOT_COOL"
}
Proposed:
enum SomeEnum {
Cool = "COOL",
NotCool = "NOT_COOL"
}
What do you think? Maybe an option?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Handbook - Enums - TypeScript
Using enums can make it easier to document intent, or create a set of distinct cases. TypeScript provides both numeric and string-based enums....
Read more >How do I make Graphql Code Generator for typescript make ...
You can set the naming convention in config in your codegen.yml file. config: namingConvention: change-case-all#pascalCase.
Read more >Swift enums: An overview with examples - LogRocket Blog
To define an enum in Swift, use the keyword enum followed by the name of the enum. The name of an enum in...
Read more >A Complete Guide to Enums in TypeScript | by Jennifer Fu
By default, enums are numeric enums, i.e. Fruit.Apple is 0, Fruit.Orange is 1, Fruit.Peach is 2, and Fruit.Pear is 3.
Read more >Is it okay to go against all-caps naming for enums to make ...
If you want the guaranteed default behavior of enum names, use name() . I don't find it "tempting" at all to rely on...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I recently encountered this when I needed to map enums in my schema to enums owned by another service. To preserve the enum values as-is (e.g.
MY_ENUM_VALUE
->MY_ENUM_VALUE
) you can use thenamingConventions
config in codegen:If that still doesn’t do what you’d like, you should be able to provide a custom mapper
Is there any way to prevent this @dotansimha ? This change has messed up my rather large code base now cause all Enums have changed…
EDIT: This is not the first time this has happened with this project (The last pascal-case things caused big headaches too). Please consider making changes backwards-compatible, as in at least always provide an option to keep previous behaviour. If you have done so for this change, I appreciate it- but as of now I can’t find any documentation on how to keep the old behaviour.