Skip to content

Commit 89a7977

Browse files
guyeoldvlprshbumkeyy
authored
TS 4.0 labeled tuple elements λ²ˆμ—­ (#177)
* labeled tuple elements κΉŒμ§€ λ²ˆμ—­ * Fix comment * Update pages/release-notes/typescript-4.0.md Co-authored-by: Kibeom Kwon <[email protected]> * Update pages/release-notes/typescript-4.0.md Co-authored-by: Seohee Park <[email protected]> * Update pages/release-notes/typescript-4.0.md Co-authored-by: Seohee Park <[email protected]> * Update pages/release-notes/typescript-4.0.md Co-authored-by: Seohee Park <[email protected]> * Update pages/release-notes/typescript-4.0.md Co-authored-by: Seohee Park <[email protected]> * Update pages/release-notes/typescript-4.0.md Co-authored-by: Seohee Park <[email protected]> Co-authored-by: Seohee Park <[email protected]> Co-authored-by: Kibeom Kwon <[email protected]>
1 parent 54ea7ac commit 89a7977

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

Diff for: β€Žpages/release-notes/typescript-4.0.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -190,28 +190,28 @@ f3(123, "hello");
190190
μš°λ¦¬λŠ” JavaScript에 λ‚΄μž₯된 `bind` λ©”μ„œλ“œμ˜ νƒ€μž… 체킹을 더 μž˜ν•˜κΈ° μœ„ν•΄ 이λ₯Ό ν™œμš©ν•  수 μžˆμ„ 것이라고 κΈ°λŒ€ν•©λ‹ˆλ‹€.
191191
λͺ‡ κ°€μ§€ λ‹€λ₯Έ μΆ”λ‘  κ°œμ„  및 νŒ¨ν„΄λ“€λ„ 여기에 ν¬ν•¨λ˜μ–΄ 있으며, κ°€λ³€ 인자 νŠœν”Œμ— λŒ€ν•΄ 더 μ•Œμ•„λ³΄κ³  μ‹Άλ‹€λ©΄, [the pull request](https://github.com/microsoft/TypeScript/pull/39094)λ₯Ό μ°Έκ³ ν•΄λ³΄μ„Έμš”.
192192

193-
## Labeled Tuple Elements
193+
## 라벨링된 νŠœν”Œ μš”μ†Œ (Labeled Tuple Elements)
194194

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)에 νŠœν”Œ νƒ€μž…μ„ μ‚¬μš©ν•  수 μžˆλ‹€λŠ” 생각은 μ•„μ£Ό μ€‘μš”ν•©λ‹ˆλ‹€.
197197

198-
For example, the following function that uses a tuple type as a rest parameter...
198+
예λ₯Ό λ“€μ–΄, νŠœν”Œ νƒ€μž…μ„ λ‚˜λ¨Έμ§€ 맀개 λ³€μˆ˜λ‘œ μ‚¬μš©ν•˜λŠ” λ‹€μŒ ν•¨μˆ˜λŠ”...
199199

200200
```ts
201201
function foo(...args: [string, number]): void {
202202
// ...
203203
}
204204
```
205205

206-
...should appear no different from the following function...
206+
...λ‹€μŒ ν•¨μˆ˜μ™€ λ‹€λ₯΄μ§€ μ•Šμ•„μ•Ό ν•©λ‹ˆλ‹€...
207207

208208
```ts
209209
function foo(arg0: string, arg1: number): void {
210210
// ...
211211
}
212212
```
213213

214-
...for any caller of `foo`.
214+
...`foo`의 λͺ¨λ“  ν˜ΈμΆœμžμ— λŒ€ν•΄μ„œλ„.
215215

216216
```ts
217217
// @errors: 2554
@@ -225,52 +225,52 @@ foo("hello", 42, true);
225225
foo("hello");
226226
```
227227

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+
νƒ€μž…-κ²€μ‚¬μ—λŠ” μ „ν˜€ 영ν–₯이 μ—†μ§€λ§Œ, νŠœν”Œ μœ„μΉ˜μ— 라벨이 μ—†λŠ” 것은 μ‚¬μš©ν•˜κΈ° μ–΄λ ΅κ²Œ λ§Œλ“­λ‹ˆλ‹€ - μ˜λ„λ₯Ό μ „λ‹¬ν•˜κΈ° μ–΄λ ΅μŠ΅λ‹ˆλ‹€.
231231

232-
That's why in TypeScript 4.0, tuples types can now provide labels.
232+
TypeScript 4.0μ—μ„œ νŠœν”Œ νƒ€μž…μ— 라벨을 μ œκ³΅ν•˜λŠ” μ΄μœ μž…λ‹ˆλ‹€.
233233

234234
```ts
235235
type Range = [start: number, end: number];
236236
```
237237

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+
맀개 λ³€μˆ˜ λͺ©λ‘κ³Ό νŠœν”Œ νƒ€μž… μ‚¬μ΄μ˜ 연결을 κ°•ν™”ν•˜κΈ° μœ„ν•΄, λ‚˜λ¨Έμ§€ μš”μ†Œμ™€ 선택적 μš”μ†Œμ— λŒ€ν•œ ꡬ문이 맀개 λ³€μˆ˜ λͺ©λ‘μ˜ ꡬ문을 λ°˜μ˜ν•©λ‹ˆλ‹€.
239239

240240
```ts
241241
type Foo = [first: number, second?: string, ...rest: any[]];
242242
```
243243

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+
ν•˜λ‚˜λŠ” νŠœν”Œ μš”μ†Œλ₯Ό 라벨링 ν•  λ•Œ, νŠœν”Œμ— μžˆλŠ” λ‹€λ₯Έ λͺ¨λ“  μš”μ†Œλ“€ μ—­μ‹œ 라벨링 λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€.
246246

247247
```ts
248248
// @errors: 5084
249249
type Bar = [first: string, number];
250250
```
251251

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+
이것은 μˆœμ „νžˆ λ¬Έμ„œν™”μ™€ 도ꡬλ₯Ό μœ„ν•΄ ν•„μš”ν•©λ‹ˆλ‹€.
254254

255255
```ts
256256
function foo(x: [first: string, second: number]) {
257257
// ...
258258

259-
// note: we didn't need to name these 'first' and 'second'
259+
// 주의: 'first'와 'second'에 λŒ€ν•΄ 이름 지을 ν•„μš” μ—†μŒ
260260
const [a, b] = x;
261261
a
262-
// ^?
262+
// ^ = const a: string
263263
b
264-
// ^?
264+
// ^ = const b: number
265265
}
266266
```
267267

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 에디터 지원은 κ°€λŠ₯ν•œ 경우 μ˜€λ²„λ‘œλ“œλ‘œ ν‘œμ‹œν•˜λ € ν•©λ‹ˆλ‹€.
270270

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)
272272

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)λ₯Ό ν™•μΈν•΄λ³΄μ„Έμš”
274274

275275
## Class Property Inference from Constructors
276276

0 commit comments

Comments
Β (0)