Skip to content

Commit 74f4bb7

Browse files
eliykataudreyality
andauthored
Fix enum-like code samples (#627)
--------- Co-authored-by: ✨ Audrey ✨ <audrey@audreyality.com>
1 parent 3556912 commit 74f4bb7

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

docs/architecture/adr/0025-ts-deprecate-enums.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ In most cases, enums are unnecessary. A readonly (`as const`) object coupled wit
3535
avoids both code generation and type inconsistencies.
3636

3737
```ts
38-
const CipherType = Object.freeze({
38+
export const CipherType = Object.freeze({
3939
Login: 1,
4040
SecureNote: 2,
4141
Card: 3,
4242
Identity: 4,
4343
SshKey: 5,
4444
} as const);
4545

46-
export type CipherType = _CipherType[keyof typeof CipherType];
46+
export type CipherType = (typeof CipherType)[keyof typeof CipherType];
4747
```
4848

4949
This code creates a `type CipherType` that allows arguments and variables to be typed similarly to
@@ -62,6 +62,9 @@ let value: CipherType = CipherType.Login;
6262
// ❌ Do not: use type inference
6363
const array = [CipherType.Login]; // infers `number[]`
6464
let value = CipherType.Login; // infers `1`
65+
66+
// ❌ Do not: use type assertions
67+
let value = CipherType.Login as CipherType; // this operation is unsafe
6568
```
6669

6770
:::

docs/contributing/code-style/angular.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ property from your component:
206206

207207
```ts
208208
// given:
209-
const EnumLike = { Some = "some", Value: "value" };
209+
const EnumLike = { Some: "some", Value: "value" };
210210
type EnumLike = EnumLike[keyof typeof EnumLike];
211211

212212
// add the input:

0 commit comments

Comments
 (0)