1
1
---
2
2
title : Indexed Access Types
3
3
layout : docs
4
- permalink : /docs/handbook/2/indexed-access-types.html
5
- oneline : " Using Type['a'] syntax to access a subset of a type. "
4
+ permalink : /ko/ docs/handbook/2/indexed-access-types.html
5
+ oneline : " Type['a'] 구문을 사용해서 타입의 내부 요소에 접근하기 "
6
6
---
7
7
8
- We can use an _ indexed access type _ to look up a specific property on another type:
8
+ 타입의 특정 프로퍼티를 찾기 위해서 _ 인덱싱된 접근 타입 _ 을 사용할 수 있습니다.
9
9
10
10
``` ts twoslash
11
11
type Person = { age: number ; name: string ; alive: boolean };
12
12
type Age = Person [" age" ];
13
13
// ^?
14
14
```
15
15
16
- The indexing type is itself a type, so we can use unions, ` keyof ` , or other types entirely:
16
+ 인덱싱된 타입은 그 자체로도 타입이라서 유니언, ` keyof ` 혹은 타입 전체에 사용할 수 있습니다.
17
17
18
18
``` ts twoslash
19
19
type Person = { age: number ; name: string ; alive: boolean };
@@ -29,7 +29,7 @@ type I3 = Person[AliveOrName];
29
29
// ^?
30
30
```
31
31
32
- You'll even see an error if you try to index a property that doesn't exist:
32
+ 존재하지 않는 프로퍼티를 인덱싱하려고 하면 오류가 발생합니다.
33
33
34
34
``` ts twoslash
35
35
// @errors: 2339
@@ -38,8 +38,8 @@ type Person = { age: number; name: string; alive: boolean };
38
38
type I1 = Person [" alve" ];
39
39
```
40
40
41
- Another example of indexing with an arbitrary type is using ` number ` to get the type of an array's elements .
42
- We can combine this with ` typeof ` to conveniently capture the element type of an array literal:
41
+ 또 다른 예로는 임의의 타입을 ` number ` 로 인덱싱해서 배열 요소의 타입을 가져올 수 있습니다 .
42
+ ` typeof ` 와 결합하면 편리하게 배열 리터럴의 요소 타입을 캡쳐할 수 있습니다.
43
43
44
44
``` ts twoslash
45
45
const MyArray = [
@@ -57,7 +57,8 @@ type Age2 = Person["age"];
57
57
// ^?
58
58
```
59
59
60
- You can only use types when indexing, meaning you can't use a ` const ` to make a variable reference:
60
+ 인덱싱할 때 변수 참조를 위해 사용된 ` const ` 는 사용할 수 없고, 오로지 타입만 사용 가능합니다.
61
+
61
62
62
63
``` ts twoslash
63
64
// @errors: 2538 2749
@@ -67,7 +68,7 @@ const key = "age";
67
68
type Age = Person [key ];
68
69
```
69
70
70
- However, you can use a type alias for a similar style of refactor:
71
+ 하지만, 비슷한 스타일의 리팩터로 타입 별칭을 사용할 수 있습니다.
71
72
72
73
``` ts twoslash
73
74
type Person = { age: number ; name: string ; alive: boolean };
0 commit comments