@@ -35,7 +35,6 @@ In most cases, enums are unnecessary. A readonly (`as const`) object coupled wit
3535avoids both code generation and type inconsistencies.
3636
3737``` ts
38- // declare the raw data and reduce repetition with an internal type
3938const CipherType = Object .freeze ({
4039 Login: 1 ,
4140 SecureNote: 2 ,
@@ -44,7 +43,6 @@ const CipherType = Object.freeze({
4443 SshKey: 5 ,
4544} as const );
4645
47- // derive the enum-like type from the raw data
4846export type CipherType = _CipherType [keyof typeof CipherType ];
4947```
5048
@@ -53,7 +51,7 @@ an enum.
5351
5452::: warning
5553
56- Unlike an enum, typescript lifts the type of the members of ` const CipherType ` to ` number ` . Code
54+ Unlike an enum, TypeScript lifts the type of the members of ` const CipherType ` to ` number ` . Code
5755like the following requires you explicitly type your variables:
5856
5957``` ts
@@ -75,7 +73,7 @@ let value = CipherType.Login; // infers `1`
7573- ** Deprecate enum use** - Allow enums to exist for historic or technical purposes, but prohibit the
7674 introduction of new ones. Reduce the lint to a "warning" and allow the lint to be disabled.
7775- ** Eliminate enum use** - This is the current state of affairs. Prohibit the introduction of any
78- new enum and replace all enums in the codebase with typescript objects. Prohibit disabling of the
76+ new enum and replace all enums in the codebase with TypeScript objects. Prohibit disabling of the
7977 lint.
8078
8179## Decision Outcome
@@ -85,6 +83,8 @@ Chosen option: **Deprecate enum use**
8583### Positive Consequences
8684
8785- Allows for cases where autogenerated code introduces an enum by necessity.
86+ - Literals (e.g. ` 1 ` ) convert to the enum-like type with full type safety.
87+ - Works with mapped types such as ` Record<T, U> ` and discriminated unions.
8888- Developers receive a warning in their IDE to discourage new enums.
8989- The warning can direct them to our contributing docs, where they can learn typesafe alternatives.
9090- Our compiled code size decreases when enums are replaced.
@@ -94,6 +94,7 @@ Chosen option: **Deprecate enum use**
9494
9595- Unnecessary usage may persist indefinitely on teams carrying a high tech debt.
9696- The lint increased the number of FIXME comments in the code by about 10%.
97+ - Enum-likes cannot be referenced by angular templates
9798
9899### Plan
99100
0 commit comments