We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5d554dc commit 2060cc8Copy full SHA for 2060cc8
docs/contributing/code-style/enums.md
@@ -58,6 +58,21 @@ type CipherContent =
58
| { type: typeof CipherType.SecureNote, note: EncString, ... }
59
```
60
61
+The above pattern also works with string-typed enum members:
62
+
63
+```ts
64
+// freeze to prevent member injection
65
+export const CredentialType = Object.freeze({
66
+ Password: "password",
67
+ Username: "username",
68
+ Email: "email",
69
+ SshKey: "ssh-key",
70
+} as const);
71
72
+// derive the enum-like type from the raw data
73
+export type CredentialType = CredentialType[keyof typeof CredentialType];
74
+```
75
76
:::warning
77
78
Unlike an enum, TypeScript lifts the type of the members of `const CipherType` to `number`. Code
0 commit comments