-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(MapKeys): Add MapKeys type documentation
- Loading branch information
1 parent
9424942
commit ed71c1d
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# MapKeys\<T> | ||
|
||
## ๊ฐ์ | ||
|
||
์ฃผ์ด์ง Map ํ์ `T`๋ก ๋ถํฐ ํค ํ์ ์ ์ถ์ถํด์. | ||
|
||
## ๋ฌธ๋ฒ | ||
|
||
```ts | ||
type MapKeys<T extends Map<unknown, unknown>> = | ||
T extends Map<infer K, unknown> ? K : never; | ||
``` | ||
|
||
- **T**: ํค ํ์ ์ ์ถ์ถํ Map ํ์ ์ด์์. | ||
|
||
## ์์ | ||
|
||
```ts | ||
const phoneBook: Map<'tomas' | 'sha', string> = new Map([ | ||
['tomas': '010-0000-0000'], | ||
['sha': '010-1111-1111'], | ||
]) | ||
|
||
type PhoneBookKeys = MapKeys<typeof phoneBook>; // 'tomas' | 'sha' | ||
|
||
const hashMap: Map<string, string> = new Map([ | ||
['0': 'coffee'], | ||
['1': 'dessert'] | ||
]) | ||
|
||
type HashMapKeys = MapKeys<typeof hashMap>; // string | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# MapKeys\<T> | ||
|
||
## Overview | ||
|
||
Extracts the key type from a given map type `T`. | ||
|
||
## Syntax | ||
|
||
```ts | ||
type MapKeys<T extends Map<unknown, unknown>> = | ||
T extends Map<infer K, unknown> ? K : never; | ||
``` | ||
|
||
- **T**: The map type from which to extract the key type. | ||
|
||
## Examples | ||
|
||
```ts | ||
const phoneBook: Map<'tomas' | 'sha', string> = new Map([ | ||
['tomas': '010-0000-0000'], | ||
['sha': '010-1111-1111'], | ||
]) | ||
|
||
type PhoneBookKeys = MapKeys<typeof phoneBook>; // 'tomas' | 'sha' | ||
|
||
const hashMap: Map<string, string> = new Map([ | ||
['0': 'coffee'], | ||
['1': 'dessert'] | ||
]) | ||
|
||
type HashMapKeys = MapKeys<typeof hashMap>; // string | ||
``` |