@@ -5,30 +5,30 @@ permalink: /ko/docs/handbook/release-notes/typescript-4-9.html
5
5
oneline : TypeScript 4.9 λ¦΄λ¦¬μ¦ λ
ΈνΈ
6
6
---
7
7
8
- ## The ` satisfies ` Operator
8
+ ## ` satisfies ` μ°μ°μ
9
9
10
- TypeScript developers are often faced with a dilemma: we want to ensure that some expression * matches * some type, but also want to keep the * most specific * type of that expression for inference purposes .
10
+ TypeScript κ°λ°μλ€μ μ’
μ’
λλ λ§μ μ§λ©΄ν©λλ€. μ°λ¦¬λ μΌλΆ ννμμ΄ νμ
κ³Ό * μΌμΉ * νλμ§ νμΈνκ³ μΆμ§λ§, μΆλ‘ μ μν΄ ννμμ * κ°μ₯ ꡬ체μ μΈ νμ
* μ μ μ§νκ³ μΆμ λκ° μμ΅λλ€ .
11
11
12
- For example:
12
+ μλ₯Ό λ€μ΄
13
13
14
14
``` ts
15
- // Each property can be a string or an RGB tuple .
15
+ // κ° μμ±μ λ¬Έμμ΄ λλ RGB ννμΌ μ μμ΅λλ€ .
16
16
const palette = {
17
17
red: [255 , 0 , 0 ],
18
18
green: " #00ff00" ,
19
19
bleu: [0 , 0 , 255 ]
20
- // ^^^^ sacrebleu - we've made a typo !
20
+ // ^^^^ sacrebleu - μ€νλ₯Ό λμ΅λλ€ !
21
21
};
22
22
23
- // We want to be able to use array methods on 'red'...
23
+ // μ°λ¦¬λ λ°°μ΄ λ©μλλ₯Ό 'red'μ μ¬μ©νκ³ μΆμ΅λλ€ ...
24
24
const redComponent = palette .red .at (0 );
25
25
26
- // or string methods on 'green'...
26
+ // νΉμ 'green'μ λ¬Έμμ΄ λ©μλλ₯Ό μ¬μ©νκ³ μΆμ μ μμ΅λλ€ ...
27
27
const greenNormalized = palette .green .toUpperCase ();
28
28
```
29
29
30
- Notice that we've written ` bleu ` , whereas we probably should have written ` blue ` .
31
- We could try to catch that ` bleu ` typo by using a type annotation on ` palette ` , but we'd lose the information about each property .
30
+ μ°λ¦¬λ ` bleu ` λμ , ` blue ` λ₯Ό μΌμ΄μΌ νμ΅λλ€ .
31
+ ` palette ` μ νμ
μ νκΈ°ν΄μ ` bleu ` μ€νλ₯Ό μ‘μ μλ μμ§λ§, κ·Έλ κ² λλ©΄ κ° μμ±μ λν μ 보λ₯Ό μκ² λ©λλ€ .
32
32
33
33
``` ts
34
34
type Colors = " red" | " green" | " blue" ;
@@ -39,15 +39,15 @@ const palette: Record<Colors, string | RGB> = {
39
39
red: [255 , 0 , 0 ],
40
40
green: " #00ff00" ,
41
41
bleu: [0 , 0 , 255 ]
42
- // ~~~~ The typo is now correctly detected
42
+ // ~~~~ μ΄μ μ€νλ₯Ό μ¬λ°λ₯΄κ² κ°μ§νμ΅λλ€.
43
43
};
44
44
45
- // But we now have an undesirable error here - 'palette.red' "could" be a string .
45
+ // νμ§λ§ μ¬κΈ°μ μμΉ μλ λ¬Έμ κ° λ°μνμ΅λλ€. 'palette.red'κ° λ¬Έμμ΄μ΄ "λ μ μλ€"λκ² μ
λλ€ .
46
46
const redComponent = palette .red .at (0 );
47
47
```
48
48
49
- The new ` satisfies ` operator lets us validate that the type of an expression matches some type, without changing the resulting type of that expression .
50
- As an example, we could use ` satisfies ` to validate that all the properties of ` palette ` are compatible with ` string | number[] ` :
49
+ ` satisfies ` μ°μ°μλ₯Ό μ¬μ©νλ©΄ ννμμ κ²°κ³Ό νμ
μ λ³κ²½νμ§ μκ³ ννμμ νμ
μ΄ νΉμ νμ
κ³Ό μΌμΉνλμ§ κ²μ¦ν μ μμ΅λλ€ .
50
+ μλ₯Ό λ€μ΄, μ°λ¦¬λ ` satisfies ` λ₯Ό μ¬μ©νμ¬ ` palette ` μ λͺ¨λ μμ±μ΄ ` string | number[] ` μ νΈνλλμ§ κ²μ¦ν μ μμ΅λλ€.
51
51
52
52
``` ts
53
53
type Colors = " red" | " green" | " blue" ;
@@ -58,35 +58,35 @@ const palette = {
58
58
red: [255 , 0 , 0 ],
59
59
green: " #00ff00" ,
60
60
bleu: [0 , 0 , 255 ]
61
- // ~~~~ The typo is now caught !
61
+ // ~~~~ μ€νκ° μ‘νμ΅λλ€ !
62
62
} satisfies Record <Colors , string | RGB >;
63
63
64
- // Both of these methods are still accessible !
64
+ // λ λ©μλ λͺ¨λ μ¬μ ν μ κ·Όν μ μμ΅λλ€ !
65
65
const redComponent = palette .red .at (0 );
66
66
const greenNormalized = palette .green .toUpperCase ();
67
67
```
68
68
69
- ` satisfies ` can be used to catch lots of possible errors .
70
- For example, we could ensure that an object has * all * the keys of some type, but no more:
69
+ ` satisfies ` λ λ§μ μ€λ₯λ₯Ό νμ§νλλ° μ¬μ©ν μ μμ΅λλ€ .
70
+ μλ₯Ό λ€λ©΄, κ°μ²΄κ° νΉμ νμ
μ * λͺ¨λ * ν€λ₯Ό κ°μ§μ§λ§, κ·Έ μ΄μμ κ°μ§μ§ μλλ‘ ν μ μμ΅λλ€.
71
71
72
72
``` ts
73
73
type Colors = " red" | " green" | " blue" ;
74
74
75
- // Ensure that we have exactly the keys from 'Colors'.
75
+ // 'Colors' ν€κ° μ ννμ§ νμΈν©λλ€ .
76
76
const favoriteColors = {
77
77
" red" : " yes" ,
78
78
" green" : false ,
79
79
" blue" : " kinda" ,
80
80
" platypus" : false
81
- // ~~~~~~~~~~ error - "platypus" was never listed in 'Colors'.
81
+ // ~~~~~~~~~~ μλ¬ - "platypus"λ 'Colors' 리μ€νΈμ μμ΅λλ€ .
82
82
} satisfies Record <Colors , unknown >;
83
83
84
- // All the information about the 'red', 'green', and 'blue' properties are retained .
84
+ // 'red', 'green' λ° 'blue' μμ±μ λͺ¨λ μ λ³΄κ° μ μ§λ©λλ€ .
85
85
const g: boolean = favoriteColors .green ;
86
86
```
87
87
88
- Maybe we don't care about if the property names match up somehow, but we do care about the types of each property .
89
- In that case, we can also ensure that all of an object's property values conform to some type .
88
+ μ΄λ°κΈ μ°λ¦¬λ μμ± μ΄λ¦ μΌμΉ μ¬λΆλ³΄λ€ κ° μμ±μ νμ
μ κ΄μ¬μ΄ μμ μ μμ΅λλ€ .
89
+ μ΄ κ²½μ° κ°μ²΄μ λͺ¨λ μμ± κ°μ΄ μΌλΆ νμ
μ μ€μνλμ§ νμΈν μλ μμ΅λλ€ .
90
90
91
91
``` ts
92
92
type RGB = [red : number , green : number , blue : number ];
@@ -95,16 +95,16 @@ const palette = {
95
95
red: [255 , 0 , 0 ],
96
96
green: " #00ff00" ,
97
97
blue: [0 , 0 ]
98
- // ~~~~~~ error !
98
+ // ~~~~~~ μλ¬ !
99
99
} satisfies Record <string , string | RGB >;
100
100
101
- // Information about each property is still maintained .
101
+ // κ° μμ±μ λν μ 보λ κ³μ μ μ§λ©λλ€ .
102
102
const redComponent = palette .red .at (0 );
103
103
const greenNormalized = palette .green .toUpperCase ();
104
104
```
105
105
106
- For more examples, you can see the [ issue proposing this ] ( https://github.com/microsoft/TypeScript/issues/47920 ) and [ the implementing pull request] ( https://github.com/microsoft/TypeScript/pull/46827 ) .
107
- We'd like to thank [ Oleksandr Tarasiuk] ( https://github.com/a-tarasyuk ) who implemented and iterated on this feature with us .
106
+ λ λ§μ μμλ₯Ό λ³΄κ³ μΆλ€λ©΄, [ μ μν μ΄μ ] ( https://github.com/microsoft/TypeScript/issues/47920 ) μ [ μ΄λ₯Ό ꡬνν pull request] ( https://github.com/microsoft/TypeScript/pull/46827 ) λ₯Ό νμΈνμΈμ .
107
+ μ°λ¦¬μ ν¨κ» μ΄ κΈ°λ₯μ ꡬνν [ Oleksandr Tarasiuk] ( https://github.com/a-tarasyuk ) μκ² κ°μ¬λ립λλ€ .
108
108
109
109
## Unlisted Property Narrowing with the ` in ` Operator
110
110
0 commit comments