Skip to content

Commit e59b0d3

Browse files
authored
Update README.md
1 parent e7b32da commit e59b0d3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,29 @@ Overflow text
8383
- Corepack for nodejs
8484
- Object.groupBy, Map.groupBy
8585

86+
### Typescript
87+
- Union type
88+
```typescript
89+
const obj = {
90+
'1': 'apple',
91+
'2': 'banana',
92+
'3': 'cherry',
93+
} as const satisfies Record<string, string>;
94+
95+
type KeyUnion = keyof typeof apiData; // '1' | '2' | '3'
96+
type ValueUnion = typeof apiData[keyof typeof apiData]; // 'apple' | 'banana' | 'cherry'
97+
```
98+
```typescript
99+
const obj = {
100+
'1': 'a',
101+
'2': 'b',
102+
'3': 'c',
103+
} as const;
104+
105+
type KeyUnion = keyof typeof obj; // '1' | '2' | '3'
106+
type ValueUnion = typeof obj[keyof typeof obj]; // 'a' | 'b' | 'c'
107+
```
108+
86109
### React
87110
- Event type quick
88111
```typescript

0 commit comments

Comments
 (0)