-
Notifications
You must be signed in to change notification settings - Fork 128
Translate 1 file to ko, playground - Variadic Tuples #92
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
Open
yahma25
wants to merge
12
commits into
microsoft:main
Choose a base branch
from
yahma25:Translation-to-ko-playground-Variadic-Tuples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d671879
Translate 1 file to ko, playground - Variadic Tuples
yahma25 727cfe4
Update docs/playground/ko/4-0/New TS Features/Variadic Tuples.ts
yahma25 f0181f3
Update docs/playground/ko/4-0/New TS Features/Variadic Tuples.ts
yahma25 496d4bf
Update docs/playground/ko/4-0/New TS Features/Variadic Tuples.ts
yahma25 4dd3872
Update docs/playground/ko/4-0/New TS Features/Variadic Tuples.ts
yahma25 3f37ba0
Update docs/playground/ko/4-0/New TS Features/Variadic Tuples.ts
yahma25 0e6aef9
Update docs/playground/ko/4-0/New TS Features/Variadic Tuples.ts
yahma25 37b9284
Update docs/playground/ko/4-0/New TS Features/Variadic Tuples.ts
yahma25 722a29e
Fix the JSON.parse error
yahma25 7b292e9
Remove 1 space
yahma25 f7caedf
Update docs/playground/ko/4-0/New TS Features/Variadic Tuples.ts
yahma25 d204567
Update docs/playground/ko/4-0/New TS Features/Variadic Tuples.ts
yahma25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//// { compiler: { ts: "4.0.2" } } | ||
// 가변 튜플은 제네릭이 동작하는 방식처럼 타입을 타입 검사기에 전달하기 위해 | ||
// 나머지 연산자(...)를 처리하는 기능을 튜플에게 제공합니다. | ||
|
||
// 꽤 고급 주제라서 이해하기 어렵더라도 너무 걱정하지 마세요. | ||
// example:generic-functions 그리고 example:tuples를 기반으로 합니다. | ||
|
||
// 먼저 튜플 앞에 항상 숫자를 붙이는 | ||
// 항상 앞에 붙이는 가변 튜플이 있습니다: | ||
|
||
type AddMax<T extends unknown[]> = [max: number, ...rest: T]; | ||
// ^ T를 제한하기 위해 사용한 제네릭 | ||
// ^ 어디에 병합하는지 나타내기 위해 사용한 ... | ||
|
||
// 합성할 때 사용 할 수 있습니다: | ||
type MaxMin = AddMax<[min: number]> | ||
type MaxMinDiameter = AddMax<[min: number, diameter: number]> | ||
|
||
// 튜플 뒤에도 동일하게 사용 할 수 있습니다: | ||
type SuffixDIContext<T extends unknown[]> = [...first: T, context: any]; | ||
type DIContainer = SuffixDIContext<[param: string]> | ||
|
||
// 이 메커니즘은 여러 개의 입력 매개변수와 합칠 수 있습니다. | ||
// 예를 들어, 이 함수는 두 개의 배열을 병합하지만 | ||
// 배열이 시작, 중단하는 곳을 나타내기 위해 '\0' 기호를 사용합니다. | ||
function joinWithNullTerminators<T extends unknown[], U extends unknown[]>(t: [...T], u: [...U]) { | ||
return ['\0', ...t, '\0', ...u, '\0'] as const; | ||
} | ||
|
||
// TypeScript는 다음과 같이 함수의 반환 타입을 추론할 수 있습니다: | ||
const result = joinWithNullTerminators(['variadic', 'types'], ["terminators", 3]); | ||
|
||
// 이런 도구를 사용하여 함수형 프로그래밍에서 자주 사용되는 개념인 | ||
// curry 함수처럼 올바르게 입력 할 수 있습니다: | ||
yahma25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function curry<T extends unknown[], U extends unknown[], R>(f: (...args: [...T, ...U]) => R, ...a: T) { | ||
return (...b: U) => f(...a, ...b); | ||
} | ||
|
||
// 세 가지 제네릭 인수가 있습니다: | ||
// - T: curry 함수에 입력 배열인 매개변수 | ||
// - U: curry 함수에 _전달되지 않고_ 반환 함수에 적용하기 위해 필요한 매개변수 | ||
// - R: 함수에 전달한 반환 타입 | ||
|
||
const sum = (left: number, right: number,) => left + right | ||
|
||
const a = curry(sum, 1, 2) | ||
const b = curry(sum, 1)(2) | ||
const c = curry(sum)(1, 2) | ||
|
||
// 여기에서 더 많은 코드 예시와 자세한 설명을 확인할 수 있습니다. | ||
// https://github.com/microsoft/TypeScript/pull/39094 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.