@@ -190,28 +190,28 @@ f3(123, "hello");
190
190
μ°λ¦¬λ JavaScriptμ λ΄μ₯λ ` bind ` λ©μλμ νμ
체νΉμ λ μνκΈ° μν΄ μ΄λ₯Ό νμ©ν μ μμ κ²μ΄λΌκ³ κΈ°λν©λλ€.
191
191
λͺ κ°μ§ λ€λ₯Έ μΆλ‘ κ°μ λ° ν¨ν΄λ€λ μ¬κΈ°μ ν¬ν¨λμ΄ μμΌλ©°, κ°λ³ μΈμ ννμ λν΄ λ μμλ³΄κ³ μΆλ€λ©΄, [ the pull request] ( https://github.com/microsoft/TypeScript/pull/39094 ) λ₯Ό μ°Έκ³ ν΄λ³΄μΈμ.
192
192
193
- ## Labeled Tuple Elements
193
+ ## λΌλ²¨λ§λ νν μμ ( Labeled Tuple Elements)
194
194
195
- Improving the experience around tuple types and parameter lists is important because it allows us to get strongly typed validation around common JavaScript idioms - really just slicing and dicing argument lists and passing them to other functions .
196
- The idea that we can use tuple types for rest parameters is one place where this is crucial .
195
+ νν νμ
κ³Ό λ§€κ° λ³μ λͺ©λ‘μ λν΄ κ°μ νλ κ²μ μΌλ°μ μΈ JavaScript κ΄μ©κ΅¬μ λν νμ
μ ν¨μ± κ²μ¬λ₯Ό κ°νμμΌμ£ΌκΈ° λλ¬Έμ μ€μν©λλ€ - μ€μ λ‘ μΈμ λͺ©λ‘μ μλ₯΄κ³ λ€λ₯Έ ν¨μλ‘ μ λ¬λ§ ν΄μ£Όλ©΄ λ©λλ€ .
196
+ λλ¨Έμ§ λ§€κ° λ³μ( rest parameter)μ νν νμ
μ μ¬μ©ν μ μλ€λ μκ°μ μμ£Ό μ€μν©λλ€ .
197
197
198
- For example, the following function that uses a tuple type as a rest parameter ...
198
+ μλ₯Ό λ€μ΄, νν νμ
μ λλ¨Έμ§ λ§€κ° λ³μλ‘ μ¬μ©νλ λ€μ ν¨μλ ...
199
199
200
200
``` ts
201
201
function foo(... args : [string , number ]): void {
202
202
// ...
203
203
}
204
204
```
205
205
206
- ...should appear no different from the following function ...
206
+ ...λ€μ ν¨μμ λ€λ₯΄μ§ μμμΌ ν©λλ€ ...
207
207
208
208
``` ts
209
209
function foo(arg0 : string , arg1 : number ): void {
210
210
// ...
211
211
}
212
212
```
213
213
214
- ...for any caller of ` foo ` .
214
+ ...` foo ` μ λͺ¨λ νΈμΆμμ λν΄μλ .
215
215
216
216
``` ts
217
217
// @errors: 2554
@@ -225,52 +225,52 @@ foo("hello", 42, true);
225
225
foo (" hello" );
226
226
```
227
227
228
- There is one place where the differences begin to become observable though: readability .
229
- In the first example, we have no parameter names for the first and second elements .
230
- While these have no impact on type-checking, the lack of labels on tuple positions can make them harder to use - harder to communicate our intent .
228
+ κ·Έλ¬λ μ°¨μ΄μ μ΄ λ³΄μ΄κΈ° μμν λΆλΆμ: κ°λ
μ±μ
λλ€ .
229
+ 첫 λ²μ§Έ μμμμλ, 첫 λ²μ§Έμ λ λ²μ§Έ μμμ λν λ§€κ° λ³μ μ΄λ¦μ΄ μμ΅λλ€ .
230
+ νμ
-κ²μ¬μλ μ ν μν₯μ΄ μμ§λ§, νν μμΉμ λΌλ²¨μ΄ μλ κ²μ μ¬μ©νκΈ° μ΄λ ΅κ² λ§λλλ€ - μλλ₯Ό μ λ¬νκΈ° μ΄λ ΅μ΅λλ€ .
231
231
232
- That's why in TypeScript 4.0, tuples types can now provide labels .
232
+ TypeScript 4.0μμ νν νμ
μ λΌλ²¨μ μ 곡νλ μ΄μ μ
λλ€ .
233
233
234
234
``` ts
235
235
type Range = [start : number , end : number ];
236
236
```
237
237
238
- To deepen the connection between parameter lists and tuple types, the syntax for rest elements and optional elements mirrors the syntax for parameter lists .
238
+ λ§€κ° λ³μ λͺ©λ‘κ³Ό νν νμ
μ¬μ΄μ μ°κ²°μ κ°ννκΈ° μν΄, λλ¨Έμ§ μμμ μ νμ μμμ λν κ΅¬λ¬Έμ΄ λ§€κ° λ³μ λͺ©λ‘μ ꡬ문μ λ°μν©λλ€ .
239
239
240
240
``` ts
241
241
type Foo = [first : number , second ? : string , ... rest : any []];
242
242
```
243
243
244
- There are a few rules when using labeled tuples .
245
- For one, when labeling a tuple element, all other elements in the tuple must also be labeled .
244
+ λΌλ²¨λ§ λ ννμ μ¬μ©ν λλ λͺ κ°μ§ κ·μΉμ΄ μμ΅λλ€ .
245
+ νλλ νν μμλ₯Ό λΌλ²¨λ§ ν λ, ννμ μλ λ€λ₯Έ λͺ¨λ μμλ€ μμ λΌλ²¨λ§ λμ΄μΌ ν©λλ€ .
246
246
247
247
``` ts
248
248
// @errors: 5084
249
249
type Bar = [first : string , number ];
250
250
```
251
251
252
- It's worth noting - labels don't require us to name our variables differently when destructuring .
253
- They're purely there for documentation and tooling .
252
+ λΉμ°νκ²λ - λΌλ²¨μ ꡬ쑰 λΆν΄ν λ λ³μ μ΄λ¦μ λ€λ₯΄κ² μ§μ ν νμκ° μμ΅λλ€ .
253
+ μ΄κ²μ μμ ν λ¬Έμνμ λꡬλ₯Ό μν΄ νμν©λλ€ .
254
254
255
255
``` ts
256
256
function foo(x : [first : string , second : number ]) {
257
257
// ...
258
258
259
- // note: we didn't need to name these ' first' and 'second'
259
+ // μ£Όμ: ' first'μ 'second'μ λν΄ μ΄λ¦ μ§μ νμ μμ
260
260
const [a, b] = x ;
261
261
a
262
- // ^?
262
+ // ^ = const a: string
263
263
b
264
- // ^?
264
+ // ^ = const b: number
265
265
}
266
266
```
267
267
268
- Overall, labeled tuples are handy when taking advantage of patterns around tuples and argument lists, along with implementing overloads in a type-safe way .
269
- In fact , TypeScript's editor support will try to display them as overloads when possible .
268
+ μ λ°μ μΌλ‘, λΌλ²¨λ§ λ ννμ μμ ν νμ
λ°©μμΌλ‘ μ€λ²λ‘λλ₯Ό ꡬννλ κ²κ³Ό ννκ³Ό μΈμ λͺ©λ‘μ ν¨ν΄μ νμ©ν λ νΈλ¦¬ν©λλ€ .
269
+ μ¬μ€ , TypeScript μλν° μ§μμ κ°λ₯ν κ²½μ° μ€λ²λ‘λλ‘ νμνλ € ν©λλ€ .
270
270
271
- ![ Signature help displaying a union of labeled tuples as in a parameter list as two signatures ] ( https://devblogs.microsoft.com/typescript/wp-content/uploads/sites/11/2020/08/signatureHelpLabeledTuples.gif )
271
+ ![ λΌλ²¨λ§λ ννμ μ λμΈμ λ§€κ°λ³μ λͺ©λ‘μμμ²λΌ λ κ°μ§ μκ·Έλμ²λ‘ 보μ¬μ£Όλ μκ·Έλμ² λμλ§ ] ( https://devblogs.microsoft.com/typescript/wp-content/uploads/sites/11/2020/08/signatureHelpLabeledTuples.gif )
272
272
273
- To learn more, check out [ the pull request ] ( https://github.com/microsoft/TypeScript/pull/38234 ) for labeled tuple elements.
273
+ λ μκ³ μΆμΌμλ©΄, λΌλ²¨λ§λ νν μμμ λν [ ν 리νμ€νΈ ] ( https://github.com/microsoft/TypeScript/pull/38234 ) λ₯Ό νμΈν΄λ³΄μΈμ
274
274
275
275
## Class Property Inference from Constructors
276
276
0 commit comments