File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
docs/documentation/ko/handbook-v2/Type Manipulation Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ title : Keyof Type Operator
3+ layout : docs
4+ permalink : /ko/docs/handbook/2/keyof-types.html
5+ oneline : " 타입 컨텍스트에서 keyof 연산자 사용하기"
6+ ---
7+
8+ ## ` keyof ` 타입 연산자
9+
10+ ` keyof ` 연산자는 객체 타입에서 객체의 키 값들을 숫자나 문자열 리터럴 유니언을 생성합니다.
11+ 아래 타입 P는 "x" | "y"와 동일한 타입입니다.
12+
13+ ``` ts twoslash
14+ type Point = { x: number ; y: number };
15+ type P = keyof Point ;
16+ // ^?
17+ ```
18+
19+ 만약 타입이 ` string ` 이나 ` number ` 인덱스 시그니쳐를 가지고 있다면, ` keyof ` 는 해당 타입을 리턴합니다.
20+
21+ ``` ts twoslash
22+ type Arrayish = { [n : number ]: unknown };
23+ type A = keyof Arrayish ;
24+ // ^?
25+
26+ type Mapish = { [k : string ]: boolean };
27+ type M = keyof Mapish ;
28+ // ^?
29+ ```
30+
31+ 위 예제에서 주목할 점은 ` M ` 은 ` string | number ` 라는 점입니다. -- JavaScript 객체 키는 항상 문자열을 강제하기 때문에, ` obj[0] ` 은 ` obj["0"] ` 과 동일합니다.
32+
33+ ` keyof ` 타입은 우리가 추후에 학습할 매핑된 타입과 함께 사용할 때 특히 유용합니다.
You can’t perform that action at this time.
0 commit comments