Skip to content

Commit 93ecc72

Browse files
committed
translation 4 files
1 parent 5a97f71 commit 93ecc72

File tree

4 files changed

+200
-0
lines changed

4 files changed

+200
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// { compiler: { noImplicitAny: false }, order: 2 }
2+
3+
// TypeScript 3.7 버전에 있는 '사용 빈도 수에 따른(infer from usage)' 코드 수정은
4+
// 더욱 똑똑해졌습니다. 이제부터는 알려진 중요한
5+
// 타입(문자열, 숫자, 배열, 프로미스)의 리스트로 사용되며,
6+
// 이러한 객체의 API와 일치하는 타입의 사용에 따라
7+
// 유추합니다.
8+
9+
// 다음과 같은 예시에서, 함수의 매개변수를 선택하고
10+
// 전구를 클릭하여, "Infer Parameter types..."를
11+
// 선택합니다.
12+
13+
// 숫자 배열을 유추합니다:
14+
15+
function pushNumber(arr) {
16+
arr.push(12);
17+
}
18+
19+
// 프로미스를 유추합니다:
20+
21+
function awaitPromise(promise) {
22+
promise.then((value) => console.log(value));
23+
}
24+
25+
// 함수를 유추하고, 다음은 반환 타입입니다:
26+
27+
function inferAny(app) {
28+
const result = app.use("hi");
29+
return result;
30+
}
31+
32+
// 문자열이 추가 되었음으로,
33+
// 문자열 배열로 유추합니다:
34+
35+
function insertString(names) {
36+
names[1] = "hello";
37+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//// { compiler: { }, order: 3 }
2+
3+
// TypeScript의 오류 메시지는 가끔 필요 이상으로 상세할 수 있습니다...
4+
// 3.7 버전에서, 몇 가지 터무니없는 사례를 보실 수 있습니다.
5+
6+
// 중첩 속성
7+
8+
let a = { b: { c: { d: { e: "string" } } } };
9+
let b = { b: { c: { d: { e: 12 } } } };
10+
11+
a = b;
12+
13+
// 이전에는, 중첩 된 속성 당 두 줄의 코드였기에,
14+
// 오류 메시지의 첫 번째와 마지막 줄을 읽음으로서
15+
// 빠르게 오류 메시지를 읽는 방법을 배웠습니다.
16+
17+
// 이제는 인라인입니다:
18+
19+
// 3.6 버전에서는 다음과 같습니다:
20+
//
21+
// Type '{ b: { c: { d: { e: number; }; }; }; }' is not assignable to type '{ b: { c: { d: { e: string; }; }; }; }'.
22+
// Types of property 'b' are incompatible.
23+
// Type '{ c: { d: { e: number; }; }; }' is not assignable to type '{ c: { d: { e: string; }; }; }'.
24+
// Types of property 'c' are incompatible.
25+
// Type '{ d: { e: number; }; }' is not assignable to type '{ d: { e: string; }; }'.
26+
// Types of property 'd' are incompatible.
27+
// Type '{ e: number; }' is not assignable to type '{ e: string; }'.
28+
// Types of property 'e' are incompatible.
29+
// Type 'number' is not assignable to type 'string'
30+
31+
// 유용하고 간결한 오류 메시지를 제공하여,
32+
// 객체의 여러 타입을 통해 작업을 처리할 수 있습니다.
33+
34+
class ExampleClass {
35+
state = "ok";
36+
}
37+
38+
class OtherClass {
39+
state = 12;
40+
}
41+
42+
let x = { a: { b: { c: { d: { e: { f: ExampleClass } } } } } };
43+
let y = { a: { b: { c: { d: { e: { f: OtherClass } } } } } };
44+
x = y;
45+
46+
// 3.6 버전에서는 다음과 같습니다:
47+
//
48+
// Type '{ a: { b: { c: { d: { e: { f: typeof OtherClass; }; }; }; }; }; }' is not assignable to type '{ a: { b: { c: { d: { e: { f: typeof ExampleClass; }; }; }; }; }; }'.
49+
// Types of property 'a' are incompatible.
50+
// Type '{ b: { c: { d: { e: { f: typeof OtherClass; }; }; }; }; }' is not assignable to type '{ b: { c: { d: { e: { f: typeof ExampleClass; }; }; }; }; }'.
51+
// Types of property 'b' are incompatible.
52+
// Type '{ c: { d: { e: { f: typeof OtherClass; }; }; }; }' is not assignable to type '{ c: { d: { e: { f: typeof ExampleClass; }; }; }; }'.
53+
// Types of property 'c' are incompatible.
54+
// Type '{ d: { e: { f: typeof OtherClass; }; }; }' is not assignable to type '{ d: { e: { f: typeof ExampleClass; }; }; }'.
55+
// Types of property 'd' are incompatible.
56+
// Type '{ e: { f: typeof OtherClass; }; }' is not assignable to type '{ e: { f: typeof ExampleClass; }; }'.
57+
// Types of property 'e' are incompatible.
58+
// Type '{ f: typeof OtherClass; }' is not assignable to type '{ f: typeof ExampleClass; }'.
59+
// Types of property 'f' are incompatible.
60+
// Type 'typeof OtherClass' is not assignable to type 'typeof ExampleClass'.
61+
// Type 'OtherClass' is not assignable to type 'ExampleClass'.
62+
// Types of property 'state' are incompatible.
63+
// Type 'number' is not assignable to type 'string'
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
display: "jsxImportSource"
3+
oneline: "Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.`"
4+
---
5+
6+
Typescript 4.1 버전에 소개 된 [jsx](#jsx)`"react-jsx"` 또는 `"react-jsxdev"`
7+
사용 할 때, `jsx``jsxs` 내장 함수를 import하여 사용하는
8+
모듈 지정자(module specifier)를 선언합니다.
9+
10+
[React 17](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)에서, 라이브러리는 독립 된 import를 통하여 새로운 형태의 JSX 변환을 지원해줍니다.
11+
12+
예를 들어:
13+
14+
```tsx
15+
import React from "react";
16+
17+
function App() {
18+
return <h1>Hello World</h1>;
19+
}
20+
```
21+
22+
TSConfig 사용할 때:
23+
24+
```json tsconfig
25+
{
26+
"compilerOptions": {
27+
"target": "esnext",
28+
"module": "commonjs",
29+
"jsx": "react-jsx"
30+
}
31+
}
32+
```
33+
34+
TypeScript에서 컴파일 된 JavaScript는:
35+
36+
```tsx twoslash
37+
// @showEmit
38+
// @noErrors
39+
// @jsx: react-jsx
40+
// @module: commonjs
41+
// @target: esnext
42+
declare module JSX {
43+
interface Element {}
44+
interface IntrinsicElements {
45+
[s: string]: any;
46+
}
47+
}
48+
import React from "react";
49+
50+
function App() {
51+
return <h1>Hello World</h1>;
52+
}
53+
```
54+
55+
예를 들어, `"jsxImportSource": "preact"`를 사용하고 싶으시면, 다음과 같은 tsconfig를 이용하시면 됩니다:
56+
57+
```json tsconfig
58+
{
59+
"compilerOptions": {
60+
"target": "esnext",
61+
"module": "commonjs",
62+
"jsx": "react-jsx",
63+
"jsxImportSource": "preact",
64+
"types": ["preact"]
65+
}
66+
}
67+
```
68+
69+
다음과 같은 코드를 생성합니다:
70+
71+
```tsx twoslash
72+
// @showEmit
73+
// @jsxImportSource: preact
74+
// @types: preact
75+
// @jsx: react-jsx
76+
// @target: esnext
77+
// @module: commonjs
78+
// @noErrors
79+
80+
export function App() {
81+
return <h1>Hello World</h1>;
82+
}
83+
```
84+
85+
또는, 파일 별 프래그마(per-file pragma)를 이용하여 다음과 같은 옵션을 설정할 수 있습니다:
86+
87+
```tsx
88+
/** @jsxImportSource preact */
89+
90+
export function App() {
91+
return <h1>Hello World</h1>;
92+
}
93+
```
94+
95+
`_jsx`팩토리를 위한 import로서 `preact/jsx-runtime`를 추가합니다.
96+
97+
_노트:_ 의도한 대로 작동이 되려면, `tsx`파일은 `export` 또는 `import`를 추가해야만, 모듈로 간주됩니다.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### 루트 필드(Root Fields)
2+
3+
TSConfig의 시작은 루트 옵션입니다 - 이러한 옵션은 TypeScript 또는 JavaScript 프로젝트 설정과 관련이 있습니다.

0 commit comments

Comments
 (0)