|
1 | 1 | ---
|
2 |
| -title: JS Projects Utilizing TypeScript |
3 |
| -layout: docs |
4 |
| -permalink: /docs/handbook/intro-to-js-ts.html |
5 |
| -oneline: How to add type checking to JavaScript files using TypeScript |
| 2 | +์ ๋ชฉ: TypeScript๋ฅผ ํ์ฉํ JS ํ๋ก์ ํธ(JS Projects Utilizing TypeScript) |
| 3 | +๋ ์ด์์: ๋ฌธ์ |
| 4 | +๊ณ ์ ๋งํฌ: /docs/handbook/intro-to-js-ts.html |
| 5 | +ํ ์ค ์ค๋ช
: TypeScript๋ฅผ ์ฌ์ฉํ์ฌ JavaScript ํ์ผ์ ์ ํ ํ์ธ์ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ |
6 | 6 | ---
|
7 | 7 |
|
8 |
| -The type system in TypeScript has different levels of strictness when working with a codebase: |
| 8 | +TypeScript์ ํ์
์์คํ
์ ์ฝ๋๋ฒ ์ด์ค๋ก ์์
ํ ๋ ์๊ฒฉํจ์ ๋ ๋ฒจ์ด ๋ค๋ฆ
๋๋ค |
9 | 9 |
|
10 |
| -* A type-system based only on inference with JavaScript code |
11 |
| -* Incremental typing in JavaScript [via JSDoc](/docs/handbook/jsdoc-supported-types.html) |
12 |
| -* Using `// @ts-check` in a JavaScript file |
13 |
| -* TypeScript code |
14 |
| -* TypeScript with [`strict`](/tsconfig#strict) enabled |
| 10 | +* ์ค์ง JavaScript ์ฝ๋์ ์ถ๋ก ์ ๊ธฐ๋ฐ์ผ๋ก ํ๋ ํ์
์์คํ
|
| 11 | +* [JSDoc๋ฅผ ํตํ](/docs/handbook/jsdoc-supported-types.html) JavaScript์์์ Incremental typing |
| 12 | +* JavaScript์์์ `// @ts-check` ์ฌ์ฉ |
| 13 | +* TypeScript ์ฝ๋ |
| 14 | +* [`strict`](/tsconfig#strict)์ด ํ์ฑํ๋ TypeScript |
15 | 15 |
|
16 |
| -Each step represents a move towards a safer type-system, but not every project needs that level of verification. |
| 16 | +๊ฐ ๋จ๊ณ๋ ํ์
์์คํ
์ ๋ ์์ ํ๊ฒ ๋ง๋ค์ง๋ง, ๋ฐ๋์ ๋ชจ๋ ํ๋ก์ ํธ๊ฐ ์ด ์์ค์ ๋ง๋ ๊ฒ์ฆ์ ํ์๋ก ํ๋ ๊ฒ์ ์๋๋๋ค. |
17 | 17 |
|
18 |
| -## TypeScript with JavaScript |
| 18 | +## JavaScript๋ฅผ ํ์ฉํ TypeScript (TypeScript with JavaScript) |
19 | 19 |
|
20 |
| -This is when you use an editor which uses TypeScript to provide tooling like auto-complete, jump to symbol and refactoring tools like rename. |
21 |
| -The [homepage](/) has a list of editors which have TypeScript plugins. |
| 20 | +์ด๋ ์๋ ์์ฑ, ์ฌ๋ฒ๋ก ์ด๋ ๋ฐ ์ด๋ฆ ๋ฐ๊พธ๊ธฐ์ ๊ฐ์ ๋ฆฌํฉํ ๋ง ํด์ ์ ๊ณตํ๊ธฐ ์ํด์ TypeScript๋ฅผ ์ฌ์ฉํ๋ ์๋ํฐ๋ฅผ ์ฌ์ฉํ ๋ ์ ์ฉํฉ๋๋ค. |
| 21 | +[ํํ์ด์ง](/)์๋ TypeScript ํ๋ฌ๊ทธ์ธ๋ค์ด ์๋ ํธ์ง์ ๋ชฉ๋ก์ด ์์ต๋๋ค. |
22 | 22 |
|
23 |
| -## Providing Type Hints in JS via JSDoc |
| 23 | +## JSDoc์ ํตํ์ฌ JS์ ํ์
ํํธ ์ ๊ณตํ๊ธฐ (Providing Type Hints in JS via JSDoc) |
24 | 24 |
|
25 |
| -In a `.js` file, types can often be inferred. When types can't be inferred, they can be specified using JSDoc syntax. |
| 25 | +`.js` ํ์ผ์์๋, ์ข
์ข
ํ์
๋ค์ ์ ์ถํ ์ ์์ต๋๋ค. ํ์
๋ค์ ์ ์ถํ ์ ์๋ ๊ฒฝ์ฐ, JSDoc ๊ตฌ๋ฌธ์ ์ฌ์ฉํ์ฌ ๊ตฌ์ฒด์ ์ผ๋ก ์๋ฆด ์ ์์ต๋๋ค. |
26 | 26 |
|
27 |
| -JSDoc annotations come before a declaration will be used to set the type of that declaration. For example: |
| 27 | +JSDoc ์ฃผ์์ ์ ์ธ ์์ ์์นํ๋ฉฐ ํน์ ์ ์ธ์ ํ์
์ ์ค์ ํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค. ์๋ฅผ ๋ค์ด: |
28 | 28 |
|
29 |
| -```js twoslash |
| 29 | +```js |
30 | 30 | /** @type {number} */
|
31 | 31 | var x;
|
32 | 32 |
|
33 |
| -x = 0; // OK |
34 |
| -x = false; // OK?! |
| 33 | +x = 0; // ์ฑ๊ณต |
| 34 | +x = false; // ์ฑ๊ณต?! |
35 | 35 | ```
|
36 | 36 |
|
37 |
| -You can find the full list of supported JSDoc patterns [in JSDoc Supported Types](/docs/handbook/jsdoc-supported-types.html). |
| 37 | +์ง์๋๋ JSDoc ํจํด์ ์ ์ฒด ๋ชฉ๋ก์ [JSDoc๊ฐ ์ง์ํ๋ ํ์
์์](/docs/handbook/jsdoc-supported-types.html) ์ฐพ์ ์ ์์ต๋๋ค. |
38 | 38 |
|
39 | 39 | ## `@ts-check`
|
40 | 40 |
|
41 |
| -The last line of the previous code sample would raise an error in TypeScript, but it doesn't by default in a JS project. |
42 |
| -To enable errors in your JavaScript files add: `// @ts-check` to the first line in your `.js` files to have TypeScript raise it as an error. |
| 41 | +์ด์ ์ฝ๋ ์์์ ๋ง์ง๋ง ์ค์ TypeScript์์ ์ค๋ฅ๋ฅผ ๋ฐ์์ํค์ง๋ง, JS ํ๋ก์ ํธ์์๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ค๋ฅ๋ฅผ ๋ฐ์์ํค์ง ์์ต๋๋ค. |
| 42 | +JavaScript ํ์ผ์์ ์ค๋ฅ๋ฅผ ์คํํ๋ ค๋ฉด ๋ค์์ ์ถ๊ฐํด์ผ ํฉ๋๋ค: `.js` ํ์ผ์ ์ฒซ ๋ฒ์งธ ์ค์ `// @ts-check`๋ฅผ ์ถ๊ฐํ์ฌ TypeScript๊ฐ ์ด๋ฅผ ์ค๋ฅ๋ก ์ฌ๋ฆฌ๋๋ก ํด์ผ ํฉ๋๋ค. |
43 | 43 |
|
44 |
| -```js twoslash |
| 44 | +```js |
45 | 45 | // @ts-check
|
46 | 46 | // @errors: 2322
|
47 | 47 | /** @type {number} */
|
48 | 48 | var x;
|
49 | 49 |
|
50 |
| -x = 0; // OK |
51 |
| -x = false; // Not OK |
| 50 | +x = 0; // ์ฑ๊ณต |
| 51 | +x = false; // ์ฑ๊ณต ์๋ |
52 | 52 | ```
|
53 | 53 |
|
54 |
| -If you have a lot of JavaScript files you want to add errors to then you can switch to using a [`jsconfig.json`](/docs/handbook/tsconfig-json.html). |
55 |
| -You can skip checking some files by adding a `// @ts-nocheck` comment to files. |
| 54 | +๋ง์ผ ์ค๋ฅ๋ฅผ ์ถ๊ฐํ๋ ค๋ JavaScript ํ์ผ์ด ๋ง์ ๊ฒฝ์ฐ, [`jsconfig.json`](/docs/handbook/tsconfig-json.html) ์ญ์ ์ฌ์ฉํ ์ ์์ต๋๋ค. |
| 55 | +ํ์ผ์ `// @ts-nocheck` ์ฝ๋ฉํธ๋ฅผ ์ถ๊ฐํ๋ฉด ์ผ๋ถ ํ์ผ ํ์ธ์ ๊ฑด๋๋ธ ์ ์์ต๋๋ค. |
56 | 56 |
|
57 |
| -TypeScript may offer you errors which you disagree with, in those cases you can ignore errors on specific lines by adding `// @ts-ignore` or `// @ts-expect-error` on the preceding line. |
| 57 | +TypeScript๋ ์ฐ๋ฆฌ๊ฐ ๋์ํ์ง ์๋ ์ค๋ฅ๋ค์ ์ ๊ณตํ ์๋ ์๋๋ฐ, ์ด ๊ฒฝ์ฐ ํน์ ์ค ๋งจ์์ `// @ts-ignore` ๋๋ `// @ts-expect-error`๋ฅผ ์ถ๊ฐํ์ฌ ๊ทธ ์ค์ ์ค๋ฅ๋ฅผ ๋ฌด์ํ ์ ์์ต๋๋ค. |
58 | 58 |
|
59 |
| -```js twoslash |
| 59 | +```js |
60 | 60 | // @ts-check
|
61 | 61 | /** @type {number} */
|
62 | 62 | var x;
|
63 | 63 |
|
64 |
| -x = 0; // OK |
| 64 | +x = 0; // ์ฑ๊ณต |
65 | 65 | // @ts-expect-error
|
66 |
| -x = false; // Not OK |
| 66 | +x = false; // ์ฑ๊ณต ์๋ |
67 | 67 | ```
|
68 | 68 |
|
69 |
| -To learn more about how JavaScript is interpreted by TypeScript read [How TS Type Checks JS](/docs/handbook/type-checking-javascript-files.html) |
| 69 | +JavaScript๋ฅผ TypeScript๋ก ํด์ํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์์ธํ ๋ด์ฉ์ [TS Type์ด JS๋ฅผ ์ฒดํฌํ๋ ๋ฐฉ๋ฒ](/docs/handbook/type-checking-javascript-files.html)์ ์ฐธ๊ณ ํ์๊ธฐ ๋ฐ๋๋๋ค. |
0 commit comments