@@ -5,83 +5,83 @@ permalink: /docs/handbook/declaration-files/dts-from-js.html
5
5
oneline : " How to add d.ts generation to JavaScript projects"
6
6
---
7
7
8
- [ With TypeScript 3.7 ] ( /docs/handbook/release-notes/typescript-3-7.html#--declaration-and---allowjs ) ,
9
- TypeScript added support for generating .d.ts files from JavaScript using JSDoc syntax .
8
+ [ TypeScript 3.7์์ ] ( https://www.typescriptlang.org /docs/handbook/release-notes/typescript-3-7.html#--declaration-and---allowjs) ,
9
+ TypeScript๋ JSDoc ๊ตฌ๋ฌธ์ ์ฌ์ฉํ JavaScript์์ .d.ts ํ์ผ์ ์์ฑํ ์ ์๊ฒ ๋์์ต๋๋ค .
10
10
11
- This set up means you can own the editor experience of TypeScript-powered editors without porting your project to TypeScript, or having to maintain .d.ts files in your codebase .
12
- TypeScript supports most JSDoc tags, you can find [ the reference here ] ( / docs/handbook/type-checking-javascript-files.html#supported-jsdoc) .
11
+ ์ฆ ํ๋ก์ ํธ๋ฅผ TypeScript์ ์ด์ํ๊ฑฐ๋(porting) ์ฝ๋๋ฒ ์ด์ค์ .d.ts ํ์ผ์ ์ ์งํ์ง ์๊ณ ๋ TypeScript ๊ธฐ๋ฐ ํธ์ง๊ธฐ์ ํ๊ฒฝ์ ์ ์งํ ์ ์์ต๋๋ค .
12
+ TypeScript๋ ๋๋ถ๋ถ์ JSDoc ํ๊ทธ๋ฅผ ์ง์ํ๋ฉฐ, [ ์ฐธ์กฐ ] ( https://www.typescriptlang.org/ docs/handbook/type-checking-javascript-files.html#supported-jsdoc) ์์ ์ฐพ์ ์ ์์ต๋๋ค .
13
13
14
- ## Setting up your Project to emit .d.ts files
14
+ ## .d.ts ํ์ผ ์์ฑ์ ์ํ ํ๋ก์ ํธ ์ค์ ( Setting up your Project to emit .d.ts files)
15
15
16
- To add creation of .d.ts files in your project, you will need to do up-to four steps :
16
+ .d.ts ํ์ผ์ ํ๋ก์ ํธ์์ ์์ฑํ๋ ค๋ฉด, ๋ค์๊ณผ ๊ฐ์ 4๋จ๊ณ๋ฅผ ๊ฑฐ์ณ์ผํฉ๋๋ค :
17
17
18
- * Add TypeScript to your dev dependencies
19
- * Add a ` tsconfig.json ` to configure TypeScript
20
- * Run the TypeScript compiler to generate the corresponding d.ts files for JS files
21
- * (optional) Edit your package.json to reference the types
18
+ * ๊ฐ๋ฐ ์์กด์ฑ์ TypeScript ์ถ๊ฐ
19
+ * TypeScript ์ค์ ์ ์ํด ` tsconfig.json ` ์ถ๊ฐ
20
+ * JS ํ์ผ์ ํด๋นํ๋ d.ts ํ์ผ์ ์์ฑํ๊ธฐ ์ํด TypeScript ์ปดํ์ผ ์คํ
21
+ * (์ ํ์ ์ผ๋ก) ํ์
์ ์ฐธ์กฐํ๊ธฐ ์ํ package.json ์์
22
22
23
- ### Adding TypeScript
23
+ ### TypeScript ์ถ๊ฐ ( Adding TypeScript)
24
24
25
- You can learn how to do this in our [ installation page ] ( / download) .
25
+ [ ์ค์น ํ์ด์ง ] ( https://www.typescriptlang.org/ download) ์์ ๋ฐฉ๋ฒ์ ํ์ธํ ์ ์์ต๋๋ค .
26
26
27
27
### TSConfig
28
28
29
- The TSConfig is a json5 file which configures both your compiler flags, and declare where to find files .
30
- In this case, you will want a file like the following :
29
+ TSConfig๋ ์ปดํ์ผ๋ฌ ํ๋๊ทธ๋ฅผ ๊ตฌ์ฑํ๊ณ ํ์ผ์ ์ฐพ์ ์์น๋ฅผ ์ ์ธํ๋ json5 ํ์ผ์
๋๋ค .
30
+ ์์ ๊ฐ์ ๊ฒฝ์ฐ, ๋ค์๊ณผ ๊ฐ์ ํ์ผ์ด ํ์ํฉ๋๋ค :
31
31
32
32
``` json5
33
33
{
34
- // Change this to match your project
34
+ // ํ๋ก์ ํธ์ ์๋ง๊ฒ ์์ ํ์ธ์.
35
35
include: [" src/**/*" ],
36
36
37
37
compilerOptions: {
38
- // Tells TypeScript to read JS files, as
39
- // normally they are ignored as source files
38
+ // ์ผ๋ฐ์ ์ผ๋ก ์์ค ํ์ผ๋ก ๋ฌด์๋๊ธฐ ๋๋ฌธ์,
39
+ // TypeScript๊ฐ JS ํ์ผ์ ์ฝ๋๋ก ์ง์ํฉ๋๋ค.
40
40
allowJs: true ,
41
- // Generate d.ts files
41
+ // d.ts ํ์ผ์ ์์ฑ์ํต๋๋ค.
42
42
declaration: true ,
43
- // This compiler run should
44
- // only output d.ts files
43
+ // ์ปดํ์ผ๋ฌ ์คํ์ด ์ค์ง
44
+ // d.ts ํ์ผ๋ง ์ถ๋ ฅํ๊ฒ ํฉ๋๋ค.
45
45
emitDeclarationOnly: true ,
46
- // Types should go into this directory .
47
- // Removing this would place the .d.ts files
48
- // next to the .js files
46
+ // ํ์
์ ์ด ๋๋ ํฐ๋ฆฌ ์์ ์กด์ฌํด์ผ ํฉ๋๋ค .
47
+ // ํด๋น ์ค์ ์ ์ ๊ฑฐํ๋ฉด,
48
+ // .d.ts ํ์ผ์ด .js ํ์ผ ์์ ์์ฑ๋ฉ๋๋ค.
49
49
outDir: " dist" ,
50
50
},
51
51
}
52
52
```
53
53
54
- You can learn more about the options in the [ tsconfig reference ] ( /reference ) .
55
- An alternative to using a TSConfig file is the CLI, this is the same behavior as a CLI command .
54
+ [ tsconfig ์ฐธ์กฐ ] ( /reference ) ์์ ๋ ๋ง์ ์ต์
์ ์ฐพ์ ์ ์์ต๋๋ค .
55
+ TSConfig ํ์ผ์ ์ฌ์ฉํ๋ ๋์ CLI๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค .
56
56
57
57
``` sh
58
58
npx typescript src/** /* .js --declaration --allowJs --emitDeclarationOnly --outDir types
59
59
```
60
60
61
- ## Run the compiler
61
+ ## ์ปดํ์ผ๋ฌ ์คํ ( Run the compiler)
62
62
63
- You can learn how to do this in our [ installation page ] ( / download) .
64
- You want to make sure these files are included in your package if you have the files in your project's ` .gitignore ` .
63
+ [ ์ค์น ํ์ด์ง ] ( https://www.typescriptlang.org/ download) ์์ ๋ฐฉ๋ฒ์ ํ์ธํ ์ ์์ต๋๋ค .
64
+ ํ๋ก์ ํธ์ ` .gitignore ` ์ ํ์ผ์ด ์์ ๋, ์ด๋ฌํ ํ์ผ๋ค์ด ํจํค์ง์ ํฌํจ๋์ด ์๋์ง ํ์ธํฉ๋๋ค .
65
65
66
- ## Editing the package.json
66
+ ## package.json ์์ ( Editing the package.json)
67
67
68
- TypeScript replicates the node resolution for modules in a ` package.json ` , with an additional step for finding .d.ts files .
69
- Roughly, the resolution will first check the optional ` "types" ` field, then the ` "main" ` field, and finally will try ` index.d.ts ` in the root .
68
+ TypeScript๋ .d.ts ํ์ผ์ ์ฐพ๊ธฐ ์ํ ์ถ๊ฐ ๋จ๊ณ์ ํจ๊ป ` package.json ` ์ ๋ชจ๋์ ๋ํ ๋
ธ๋ ๊ด๊ณ(node resolution)๋ฅผ ๋ณต์ ํฉ๋๋ค .
69
+ ๋๋ต์ ์ผ๋ก ๋จผ์ ์ ํ์ ์ธ ` "types" ` ํ๋๋ฅผ ํ์ธ ํ, ๋ค์์ ` "main" ` , ๋ง์ง๋ง์ผ๋ก ๋ฃจํธ์์ ` index.d.ts ` ๋ฅผ ํ์ธํฉ๋๋ค .
70
70
71
- | Package.json | Location of default .d.ts |
71
+ | Package.json | ๊ธฐ๋ณธ .d.ts์ ์์น |
72
72
| :------------------------ | :----------------------------- |
73
- | No "types" field | checks "main", then index.d.ts |
73
+ | "types" ํ๋ ์์ | "main" ํ์ธ ํ, index.d.ts ํ์ธ |
74
74
| "types": "main.d.ts" | main.d.ts |
75
75
| "types": "./dist/main.js" | ./main/main.d.ts |
76
76
77
- If absent, then "main" is used
77
+ type ํ๋๊ฐ ์๋ค๋ฉด, "main"์ผ๋ก ๋์ด๊ฐ๋๋ค.
78
78
79
- | Package.json | Location of default .d.ts |
79
+ | Package.json | ๊ธฐ๋ณธ .d.ts์ ์์น |
80
80
| :----------------------- | :------------------------ |
81
- | No "main" field | index.d.ts |
81
+ | "main" ํ๋ ์์ | index.d.ts |
82
82
| "main":"index.js" | index.d.ts |
83
83
| "main":"./dist/index.js" | ./dist/index.d.ts |
84
84
85
- ## Tips
85
+ ## ํ ( Tips)
86
86
87
- If you'd like to write tests for your .d.ts files, try [ tsd] ( https://github.com/SamVerschueren/tsd ) .
87
+ .d.ts์ ํ
์คํธ๋ฅผ ์์ฑํ๊ณ ์ถ๋ค๋ฉด, [ tsd] ( https://github.com/SamVerschueren/tsd ) ๋ฅผ ์ฌ์ฉํด๋ณด์ธ์ .
0 commit comments