1
1
---
2
2
title : Typeof Type Operator
3
3
layout : docs
4
- permalink : /docs/handbook/2/typeof-types.html
5
- oneline : " Using the typeof operator in type contexts ."
4
+ permalink : /ko/ docs/handbook/2/typeof-types.html
5
+ oneline : " 타입 컨텍스트에서 typeof 연산자 사용하기 ."
6
6
---
7
7
8
- ## The ` typeof ` type operator
8
+ ## ` typeof ` 타입 연산자
9
9
10
- JavaScript already has a ` typeof ` operator you can use in an _ expression _ context:
10
+ JavaScript에서는 이미 _ 표현식 _ 컨텍스트에서 사용할 수 있는 ` typeof ` 연산자가 있습니다.
11
11
12
12
``` ts twoslash
13
- // Prints "string"
13
+ // "string"을 출력합니다
14
14
console .log (typeof " Hello world" );
15
15
```
16
16
17
- TypeScript adds a ` typeof ` operator you can use in a _ type _ context to refer to the _ type _ of a variable or property:
17
+ TypeScript는 _ 타입 _ 컨텍스트에서 변수나 프로퍼티의 타입을 추론할 수 있는 ` typeof ` 연산자를 추가합니다.
18
18
19
19
``` ts twoslash
20
20
let s = " hello" ;
21
21
let n: typeof s ;
22
22
// ^?
23
23
```
24
24
25
- This isn't very useful for basic types, but combined with other type operators, you can use ` typeof ` to conveniently express many patterns .
26
- For an example, let's start by looking at the predefined type ` ReturnType<T> ` .
27
- It takes a _ function type _ and produces its return type:
25
+ 기본 타입에 대해선 별로 유용하진 않지만, 다른 타입 연산자와 함께 ` typeof ` 를 사용하여 많은 패턴을 편리하게 표현할 수 있습니다 .
26
+ 예를 들어, 미리 정의된 타입인 ` ReturnType<T> ` 부터 살펴보겠습니다 .
27
+ 위 타입은 _ 함수 타입 _ 을 받으면서 반환되는 타입을 제공합니다.
28
28
29
29
``` ts twoslash
30
30
type Predicate = (x : unknown ) => boolean ;
31
31
type K = ReturnType <Predicate >;
32
32
// ^?
33
33
```
34
34
35
- If we try to use ` ReturnType ` on a function name, we see an instructive error:
35
+ 함수 이름에 ` ReturnType ` 을 사용하면, 안내 오류를 확인할 수 있습니다.
36
36
37
37
``` ts twoslash
38
38
// @errors: 2749
@@ -42,8 +42,8 @@ function f() {
42
42
type P = ReturnType <f >;
43
43
```
44
44
45
- Remember that _ values _ and _ types _ aren't the same thing .
46
- To refer to the _ type _ that the _ value ` f ` _ has, we use ` typeof ` :
45
+ _ 값 _ 과 _ 타입 _ 은 같지 않다는 것을 명심하세요 .
46
+ _ 값 ` f ` _ 의 _ 타입 _ 을 추론하기 위해서 ` typeof ` 를 사용합니다.
47
47
48
48
``` ts twoslash
49
49
function f() {
@@ -53,12 +53,12 @@ type P = ReturnType<typeof f>;
53
53
// ^?
54
54
```
55
55
56
- ### Limitations
56
+ ### 제한
57
57
58
- TypeScript intentionally limits the sorts of expressions you can use ` typeof ` on .
58
+ TypeScript는 ` typeof ` 를 사용할 수 있는 표현식의 종류를 의도적으로 제한합니다 .
59
59
60
- Specifically, it's only legal to use ` typeof ` on identifiers (i.e. variable names) or their properties .
61
- This helps avoid the confusing trap of writing code you think is executing, but isn't:
60
+ 특히, 식별자(예: 변수이름) 혹은 프로퍼티에서만 ` typeof ` 를 사용할 수 있습니다 .
61
+ 실행 중인 것으로 생각되는 코드 작성의 실수를 피하는데 도움을 줄 수 있지만, 그렇진 않습니다.
62
62
63
63
``` ts twoslash
64
64
// @errors: 1005
0 commit comments