Typescript enum migration to eraseable syntax - naming convention poll #7574
Replies: 5 comments 7 replies
-
@nflaig Please be aware that with Pattern 5 there could be a lot of false positives. There can be many variable names which are not related to enum, but linter will enforce those to |
Beta Was this translation helpful? Give feedback.
-
I'm voting for 4 + 5 No linter rule (allow camel and pascal) |
Beta Was this translation helpful? Give feedback.
-
I tend to agree with @wemeetagain, Pascal and camel are both valid cases for variable names. No linter rule, or set rule for to allowing both. And for enums use plural for the values and singular for the type. I say that though with a caveat, English being the wonderfully caveated language that it is (in particular with regards to plurals) there will be inconsistencies for doing this. I tend to lean towards a suffix on either the value or the type but it seems like team consensus is strongly against that already. With the suffix veto in mind i think singular/plural is the best of the remaining options. |
Beta Was this translation helpful? Give feedback.
-
Voted 4, but prefer some suffix other than |
Beta Was this translation helpful? Give feedback.
-
After a lot of brainstorming and discussion we decided to move with const ImportStatusEnum = {
Imported: "Imported",
Duplicate: "Duplicate",
Error: "Error",
} as const;
type ImportStatus = EnumLike<typeof ImportStatusEnum>; A reference PR related to this discussion ChainSafe/benchmark#31 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
In Typescript we the struct
enum
is unique that it combine value and type information together. We want to use TS5.8eraseableSyntaxOnly
feature to adapt to future TS support in NodeJS.In that syntax we can't mix up the types and values together so we have to split all
enum
to pair of values+types manually. Take this example.Solution
This needs to be divide into two declarations , one for value and one for type. We can't use same name for both declarations so question came up what names do we use for both and how to enforce the linting rules to have consistent code.
And we want to have such naming convention that can be enforced by the linter. Our general rule is to allow
camelCase
for all variable/cost declarations but we want exception for enum values to havePascalCase
.Our linter currently can only support regular expression matching on the names of the declarations so any suffix/prefix will help us to identify if it's a enum value declaration or just a normal variable. So please vote for any of pattern below which you feel more aligned with or comment with your suggestion otherwise.
Pattern 1 - capital case enum + camelCase values
camelCase
and all type declarations arePascalCase
Pattern 2 - Capital case values with Enum suffix type
Pattern 3 - Capital case values with Values suffix type
Pattern 4 - Allow all variables to be both
PascalCase
orcamelCase
.Pattern 5 - Plural for value and singular for type
s
must bePascalCase
8 votes ·
Beta Was this translation helpful? Give feedback.
All reactions