Skip to content

Commit

Permalink
docs(MapKeys): Add MapKeys type documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
haejunejung committed Aug 29, 2024
1 parent 9424942 commit ed71c1d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/ko/reference/map/MapKeys.md
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
```
32 changes: 32 additions & 0 deletions docs/reference/map/MapKeys.md
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
```

0 comments on commit ed71c1d

Please sign in to comment.