Skip to content

TS 4.0 labeled tuple elements 번역 #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 7, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions pages/release-notes/typescript-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,28 +190,28 @@ Variadic tuple types enable a lot of new exciting patterns, especially around fu
We expect we may be able to leverage it to do a better job type-checking JavaScript's built-in `bind` method.
A handful of other inference improvements and patterns also went into this, and if you're interested in learning more, you can take a look at [the pull request](https://github.com/microsoft/TypeScript/pull/39094) for variadic tuples.

## Labeled Tuple Elements
## 라벨링된 튜플 요소 (Labeled Tuple Elements)

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.
The idea that we can use tuple types for rest parameters is one place where this is crucial.
튜플 타입과 매개 변수 목록의 경험을 개선하는 것은 일반적인 JavaScript 관용구에 대한 타입 유효성 검사를 강화시켜주기 때문에 중요합니다 - 실제로 인수 목록을 자르고 다른 함수로 전달만 해주면 됩니다.
나머지 매개 변수(rest parameter)에 튜플 타입을 사용할 수 있다는 생각은 아주 중요합니다.

For example, the following function that uses a tuple type as a rest parameter...
예를 들어, 다음 함수는 튜플 타입을 나머지 매개 변수로 사용한 예시는...

```ts
function foo(...args: [string, number]): void {
// ...
}
```

...should appear no different from the following function...
...다음 함수와 다르지 않아야 합니다...

```ts
function foo(arg0: string, arg1: number): void {
// ...
}
```

...for any caller of `foo`.
...`foo`의 모든 호출자에 대해서도.

```ts
// @errors: 2554
Expand All @@ -225,52 +225,52 @@ foo("hello", 42, true);
foo("hello");
```

There is one place where the differences begin to become observable though: readability.
In the first example, we have no parameter names for the first and second elements.
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.
그래도 차이점이 보이기 시작한 것은: 가독성입니다.
첫 번째 예시에서는, 첫 번째와 두 번째 요소에 대한 매개 변수 이름이 없습니다.
타입-검사에는 영향이 전혀 없지만, 튜플 위치에 라벨이 없는 것은 사용하기 어렵게 만듭니다 - 의도를 전달하기 어렵습니다.

That's why in TypeScript 4.0, tuples types can now provide labels.
TypeScript 4.0에서 튜플 타입에 라벨을 제공하는 이유입니다.

```ts
type Range = [start: number, end: number];
```

To deepen the connection between parameter lists and tuple types, the syntax for rest elements and optional elements mirrors the syntax for parameter lists.
매개 변수 목록과 튜플 타입 사이의 연결을 강화하려면, 나머지 요소와 선택적 요소에 대한 구문이 매개 변수 목록의 구문을 반영합니다.

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

There are a few rules when using labeled tuples.
For one, when labeling a tuple element, all other elements in the tuple must also be labeled.
라벨링 된 튜플을 사용할 때는 몇 가지 규칙이 있습니다.
하나는 튜플 요소를 라벨링 할 때, 튜플에 있는 다른 모든 요소들 역시 라벨링 되어야 합니다.

```ts
// @errors: 5084
type Bar = [first: string, number];
```

It's worth noting - labels don't require us to name our variables differently when destructuring.
They're purely there for documentation and tooling.
당연하게도 - 라벨은 구조 분해할 때 변수 이름을 다르게 지정할 필요가 없습니다.
이것은 순전히 문서화와 도구를 위해 필요합니다.

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

// note: we didn't need to name these 'first' and 'second'
// 주의: 'first''second'에 대해 이름 지을 필요 없음
const [a, b] = x;
a
// ^?
// ^ = const a: string
b
// ^?
// ^ = const b: number
}
```

Overall, labeled tuples are handy when taking advantage of patterns around tuples and argument lists, along with implementing overloads in a type-safe way.
In fact, TypeScript's editor support will try to display them as overloads when possible.
전반적으로, 라벨링 된 튜플은 안전한 타입 방식으로 오버로드를 구현하는 것과 튜플과 인수 목록의 패턴을 활용할 때 편리합니다
사실, TypeScript 에디터 지원은 가능한 경우 오버로드로 표시하려 합니다.

![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)
![라벨링된 튜플의 유니언을 매개변수 목록에서처럼 두 가지 시그니처로 보여주는 시그니처 도움말](https://devblogs.microsoft.com/typescript/wp-content/uploads/sites/11/2020/08/signatureHelpLabeledTuples.gif)

To learn more, check out [the pull request](https://github.com/microsoft/TypeScript/pull/38234) for labeled tuple elements.
더 알고 싶으시면, 라벨링된 튜플 요소에 대한 [풀 리퀘스트](https://github.com/microsoft/TypeScript/pull/38234)를 확인해보세요

## Class Property Inference from Constructors

Expand Down