Skip to content

Commit 6e8f785

Browse files
committed
Merge branch 'main' into translation/everyday-types
2 parents c28f37a + 7806361 commit 6e8f785

File tree

6 files changed

+797
-20
lines changed

6 files changed

+797
-20
lines changed

attribution.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/documentation/ko/handbook-v2/Basics.md

Lines changed: 440 additions & 0 deletions
Large diffs are not rendered by default.

docs/documentation/ko/reference/Utility Types.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ const todo2 = updateTodo(todo1, {
3434
});
3535
```
3636

37+
## `Required<Type>`
38+
39+
`Type` 집합의 모든 프로퍼티를 필수로 설정한 타입을 생성합니다. [`Partial`](#partialtype)의 반대입니다.
40+
41+
##### 예제
42+
43+
```ts twoslash
44+
// @errors: 2741
45+
interface Props {
46+
a?: number;
47+
b?: string;
48+
}
49+
50+
const obj: Props = { a: 5 };
51+
52+
const obj2: Required<Props> = { a: 5 };
53+
```
54+
3755
## `Readonly<Type>`
3856

3957
`Type` 집합의 모든 프로퍼티`읽기 전용(readonly)`으로 설정한 타입을 생성합니다, 즉 생성된 타입의 프로퍼티는 재할당될 수 없습니다.
@@ -279,24 +297,6 @@ type T4 = InstanceType<Function>;
279297
// ^?
280298
```
281299

282-
## `Required<Type>`
283-
284-
필요한 `T`집합의 모든 프로퍼티로 구성된 타입을 생성합니다. [`Partial`](#partialtype) 의 반대쪽.
285-
286-
##### 예제
287-
288-
```ts twoslash
289-
// @errors: 2741
290-
interface Props {
291-
a?: number;
292-
b?: string;
293-
}
294-
295-
const obj: Props = { a: 5 };
296-
297-
const obj2: Required<Props> = { a: 5 };
298-
```
299-
300300
## `ThisParameterType<Type>`
301301

302302
함수 타입의 [this](/docs/handbook/functions.html#this-parameters) 매개변수의 타입, 또는 함수 타입에 `this`매개변수가 없을 경우 [unknown](/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type) 을 추출합니다.
@@ -369,4 +369,13 @@ obj.moveBy(5, 5);
369369

370370
## 내장 문자열 조작 타입
371371

372-
템플릿 문자열 리터럴 주변의 문자열 조작을 돕기 위해, TypeScript는 타입 시스템 내에서 문자열 조작에 사용할 수 있는 타입 집합이 포함되어 있습니다. 할 수 있어요
372+
### `Uppercase<StringType>`
373+
374+
### `Lowercase<StringType>`
375+
376+
### `Capitalize<StringType>`
377+
378+
### `Uncapitalize<StringType>`
379+
380+
템플릿 문자열 리터럴에서의 문자열 조작을 돕기 위해, TypeScript는 타입 시스템 내에서 문자열 조작에 사용할 수 있는 타입 집합이 포함되어 있습니다.
381+
[이 링크](/docs/handbook/2/template-literal-types.html#intrinsic-string-manipulation-types)에서 예제를 확인하세요.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: tsconfig.json 是什么
3+
layout: docs
4+
permalink: /zh/docs/handbook/tsconfig-json.html
5+
oneline: 了解 TSConfig 的工作原理
6+
translatable: true
7+
---
8+
9+
## 概览
10+
11+
当目录中出现了 `tsconfig.json` 文件,则说明该目录是 TypeScript 项目的根目录。`tsconfig.json` 文件指定了编译项目所需的根目录下的文件以及编译选项。
12+
13+
JavaScript 项目可以使用 `jsconfig.json` 文件,它的作用与 `tsconfig.json` 基本相同,只是默认启用了一些 JavaScript 相关的编译选项。
14+
15+
一个项目将以下列之一的方式编译:
16+
17+
## 使用 `tsconfig.json` 或者 `jsconfig.json`
18+
19+
- 在调用 tsc 命令并且没有其它输入文件参数时,编译器将由当前目录开始向父级目录寻找包含 tsconfig 文件的目录。
20+
21+
- 调用 tsc 命令并且没有其他输入文件参数,可以使用 `--project` (或者只是 `-p`)的命令行选项来指定包含了 `tsconfig.json` 的目录,或者包含有效配置的 `.json` 文件路径。
22+
23+
当命令行中指定了输入文件参数, `tsconfig.json` 文件会被忽略。
24+
25+
## 示例
26+
27+
`tsconfig.json` 文件示例:
28+
29+
- 使用 `files` 属性
30+
31+
```json tsconfig
32+
{
33+
"compilerOptions": {
34+
"module": "commonjs",
35+
"noImplicitAny": true,
36+
"removeComments": true,
37+
"preserveConstEnums": true,
38+
"sourceMap": true
39+
},
40+
"files": [
41+
"core.ts",
42+
"sys.ts",
43+
"types.ts",
44+
"scanner.ts",
45+
"parser.ts",
46+
"utilities.ts",
47+
"binder.ts",
48+
"checker.ts",
49+
"emitter.ts",
50+
"program.ts",
51+
"commandLineParser.ts",
52+
"tsc.ts",
53+
"diagnosticInformationMap.generated.ts"
54+
]
55+
}
56+
```
57+
58+
- 使用 `"include"``"exclude"` 属性
59+
60+
```json tsconfig
61+
{
62+
"compilerOptions": {
63+
"module": "system",
64+
"noImplicitAny": true,
65+
"removeComments": true,
66+
"preserveConstEnums": true,
67+
"outFile": "../../built/local/tsc.js",
68+
"sourceMap": true
69+
},
70+
"include": ["src/**/*"],
71+
"exclude": ["node_modules", "**/*.spec.ts"]
72+
}
73+
```
74+
75+
## 基本的 TSConfig
76+
77+
根据你要在其中运行代码的不同的 JavaScript 运行时环境,你可以在 [github.com/tsconfig/bases](https://github.com/tsconfig/bases/) 上寻找一个合适的基本配置。
78+
你可以通过扩展这些已经处理过不同的 JavaScript 运行时环境的 `tsconfig.json` 文件来简化你项目中的 `tsconfig.json`
79+
80+
举个例子,如果你的项目是基于 Node.js 12.x 写的,那么你可以使用 npm 模块:[`@tsconfig/node12`](https://www.npmjs.com/package/@tsconfig/node12)
81+
82+
```json tsconfig
83+
{
84+
"extends": "@tsconfig/node12/tsconfig.json",
85+
86+
"compilerOptions": {
87+
"preserveConstEnums": true
88+
},
89+
90+
"include": ["src/**/*"],
91+
"exclude": ["node_modules", "**/*.spec.ts"]
92+
}
93+
```
94+
95+
这使你的 `tsconfig.json` 专注在你的项目的目标环境上,而不是所有可能的运行时环境。现在已经有了一些 tsconfig 基础配置,我们希望社区能够为不同的环境添加更多的内容。
96+
97+
- [推荐配置](https://www.npmjs.com/package/@tsconfig/recommended)
98+
- [Node 10](https://www.npmjs.com/package/@tsconfig/node10)
99+
- [Node 12](https://www.npmjs.com/package/@tsconfig/node12)
100+
- [Node 14](https://www.npmjs.com/package/@tsconfig/node14)
101+
- [Deno](https://www.npmjs.com/package/@tsconfig/deno)
102+
- [React Native](https://www.npmjs.com/package/@tsconfig/react-native)
103+
- [Svelte](https://www.npmjs.com/package/@tsconfig/svelte)
104+
105+
## 细节
106+
107+
当没有指定 `"compilerOptions"` 时,会使用编译器的默认配置。请参考我们支持的[编译器选项](/tsconfig)列表。
108+
109+
## TSConfig 参考
110+
111+
想要了解更多的配置选项的信息,请访问 [TSConfig Reference](/tsconfig)
112+
113+
## 协议
114+
115+
`tsconfig.json` 的协议可以在这里找到 [the JSON Schema Store](http://json.schemastore.org/tsconfig)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//// { order: 3 }
2+
3+
// 먼저 이 방식으로 이해하는 게 훨씬 쉬우므로
4+
// 예시는 대부분 TypeScript로 작성했습니다.
5+
// 마지막에는 JSDoc을 사용하여 동일한 클래스를 만드는 방법을 다룰 겁니다.
6+
7+
// 제네릭 클래스는 특정 타입이 다른 타입에 따라 동작한다는 것을 보여주는 하나의 방식입니다.
8+
// 예를 들어, 여기에는 한 종류만 있지만
9+
// 여러 가지 물건을 담을 수 있는 하나의 서랍이 있습니다:
10+
11+
class Drawer<ClothingType> {
12+
contents: ClothingType[] = [];
13+
14+
add(object: ClothingType) {
15+
this.contents.push(object);
16+
}
17+
18+
remove() {
19+
return this.contents.pop();
20+
}
21+
}
22+
23+
// Drawer를 사용하기 위해서
24+
// 또 다른 타입이 필요합니다:
25+
26+
interface Sock {
27+
color: string;
28+
}
29+
30+
interface TShirt {
31+
size: "s" | "m" | "l";
32+
}
33+
34+
// 새로운 Drawer를 만들 때 Sock 타입을 전달하여
35+
// 양말 전용의 새로운 Drawer를 만들 수 있습니다:
36+
const sockDrawer = new Drawer<Sock>();
37+
38+
// 이제 양말을 서랍에 추가하거나 삭제할 수 있습니다:
39+
sockDrawer.add({ color: "white" });
40+
const mySock = sockDrawer.remove();
41+
42+
// 티셔츠를 위한 서랍도 만들 수 있습니다:
43+
const tshirtDrawer = new Drawer<TShirt>();
44+
tshirtDrawer.add({ size: "m" });
45+
46+
// 여러분이 조금 별나신 편이라면,
47+
// 유니언을 사용하여 양말과 티셔츠가 섞인 서랍을 만들 수도 있습니다
48+
49+
const mixedDrawer = new Drawer<Sock | TShirt>();
50+
51+
// 추가 TypeScript 구문 없이 Drawer와 같은 클래스를 만드는 것은
52+
// JSDoc에서 템플릿 태그 사용을 요구합니다.
53+
// 이 예시에서 템플릿 변수를 정의하고,
54+
// 클래스에 프로퍼티를 제공할 것입니다:
55+
56+
// playground에서 작업하기 위해서,
57+
// JavaScript 파일로 설정을 변경하고
58+
// 위에 있는 TypeScript 코드를 제거해야 합니다
59+
60+
/**
61+
* @template {{}} ClothingType
62+
*/
63+
class Dresser {
64+
constructor() {
65+
/** @type {ClothingType[]} */
66+
this.contents = [];
67+
}
68+
69+
/** @param {ClothingType} object */
70+
add(object) {
71+
this.contents.push(object);
72+
}
73+
74+
/** @return {ClothingType} */
75+
remove() {
76+
return this.contents.pop();
77+
}
78+
}
79+
80+
// 그러고 나서 JSDoc을 통해 새로운 타입을 만듭니다:
81+
82+
/**
83+
* @typedef {Object} Coat 의류 아이템
84+
* @property {string} color 코트 색상
85+
*/
86+
87+
// Dresser 클래스의 새로운 인스턴스를 생성할 때
88+
// 코트를 다루는 Dresser로
89+
// 변수를 할당하기 위해 @type을 사용합니다.
90+
91+
/** @type {Dresser<Coat>} */
92+
const coatDresser = new Dresser();
93+
94+
coatDresser.add({ color: "green" });
95+
const coat = coatDresser.remove();
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//// { order: 4 }
2+
3+
// TypeScript가 지원하는 JavaScript에 있는 클래스를 위해
4+
// 가짜 다중 상속 패턴인 믹스인이 있습니다.
5+
// 다중 상속 패턴은 많은 클래스가 합쳐진
6+
// 하나의 클래스를 생성할 수 있게 해줍니다.
7+
8+
// 시작하기 위해, 다른 클래스로부터 확장하는 타입이 필요합니다.
9+
// 주요 책임은 전달받은 타입이
10+
// 하나의 클래스라고 선언하는 것입니다.
11+
12+
type Constructor = new (...args: any[]) => {};
13+
14+
// 그러고 나서 래핑하여 최종 클래스에 확장하는
15+
// 클래스 시리즈를 생성할 수 있습니다.
16+
// 비슷한 객체가 다른 능력을 갖출 때, 이 패턴은 잘 동작합니다.
17+
18+
// 믹스인은 캡슐화된 private 프로퍼티로 변경하기 위해
19+
// scale 프로퍼티를 getter와 setter를 함께 추가합니다:
20+
21+
function Scale<TBase extends Constructor>(Base: TBase) {
22+
return class extends Base {
23+
// 믹스인은 private/protected 프로퍼티를 선언할 수 없겠지만,
24+
// ES2020 private 필드를 사용할 수 있습니다
25+
_scale = 1;
26+
27+
setScale(scale: number) {
28+
this._scale = scale;
29+
}
30+
31+
get scale(): number {
32+
return this._scale;
33+
}
34+
};
35+
}
36+
37+
// 믹스인은 현대식 컴퓨터가 깊이를 만드는 데 사용하는
38+
// 알파 구성요소에 대한 추가 메서드를 추가합니다:
39+
40+
function Alpha<TBase extends Constructor>(Base: TBase) {
41+
return class extends Base {
42+
alpha = 1;
43+
44+
setHidden() {
45+
this.alpha = 0;
46+
}
47+
48+
setVisible() {
49+
this.alpha = 1;
50+
}
51+
52+
setAlpha(alpha: number) {
53+
this.alpha = alpha;
54+
}
55+
};
56+
}
57+
58+
// 확장될 간단한 스프라이트 기반 클래스:
59+
60+
class Sprite {
61+
name = "";
62+
x = 0;
63+
y = 0;
64+
65+
constructor(name: string) {
66+
this.name = name;
67+
}
68+
}
69+
70+
// 서로 다른 기능을 가진
71+
// 2개의 다른 스프라이트 타입을 만듭니다:
72+
73+
const ModernDisplaySprite = Alpha(Scale(Sprite));
74+
const EightBitSprite = Scale(Sprite);
75+
76+
// 이런 클래스의 인스턴스를 생성하는 것은
77+
// 믹스인 때문에 객체가 서로 다른
78+
// 프로퍼티와 메서드의 모음을 가진다는 것을 나타냅니다:
79+
80+
const flappySprite = new ModernDisplaySprite("Bird");
81+
flappySprite.x = 10;
82+
flappySprite.y = 20;
83+
flappySprite.setVisible();
84+
flappySprite.setScale(0.8);
85+
console.log(flappySprite.scale);
86+
87+
const gameBoySprite = new EightBitSprite("L block");
88+
gameBoySprite.setScale(0.3);
89+
90+
// EightBitSprite가 알파로 변경하기 위한
91+
// 믹스인이 없으니 실패합니다:
92+
gameBoySprite.setAlpha(0.5);
93+
94+
// 래핑한 클래스에 대해 더 많이 보장하길 원한다면,
95+
// 제네릭과 함께 생성자를 사용할 수 있습니다.
96+
97+
type GConstructor<T = {}> = new (...args: any[]) => T;
98+
99+
// 이제 이 믹스인이 기반 클래스가 특정한 형태일 때만
100+
// 적용할 수 있도록 선언할 수 있습니다.
101+
102+
type Moveable = GConstructor<{ setXYAcceleration: (x: number, y: number) => void }>;
103+
104+
// GConstructor에 대한 매개변수에 있는
105+
// 함수 존재 여부에 따라서 믹스인을 생성할 수 있습니다.
106+
107+
function Jumpable<TBase extends Moveable>(Base: TBase) {
108+
return class extends Base {
109+
jump() {
110+
// 이 믹스인은 이제 setXYAcceleration에 대하여 알고 있습니다
111+
this.setXYAcceleration(0, 20);
112+
}
113+
};
114+
}
115+
116+
// 믹스인 계층에 setXYAcceleration를 추가하는 클래스가
117+
// 존재할 때까지 이 스프라이트를 생성할 수 없습니다:
118+
const UserSprite = new Jumpable(ModernDisplaySprite);

0 commit comments

Comments
 (0)