@@ -5,83 +5,83 @@ permalink: /docs/handbook/declaration-files/dts-from-js.html
55oneline : " How to add d.ts generation to JavaScript projects"
66---
77
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 ํ์ผ์ ์์ฑํ ์ ์๊ฒ ๋์์ต๋๋ค .
1010
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) ์์ ์ฐพ์ ์ ์์ต๋๋ค .
1313
14- ## Setting up your Project to emit .d.ts files
14+ ## .d.ts ํ์ผ ์์ฑ์ ์ํ ํ๋ก์ ํธ ์ค์ ( Setting up your Project to emit .d.ts files)
1515
16- To add creation of .d.ts files in your project, you will need to do up-to four steps :
16+ .d.ts ํ์ผ์ ํ๋ก์ ํธ์์ ์์ฑํ๋ ค๋ฉด, ๋ค์๊ณผ ๊ฐ์ 4๋จ๊ณ๋ฅผ ๊ฑฐ์ณ์ผํฉ๋๋ค :
1717
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 ์์
2222
23- ### Adding TypeScript
23+ ### TypeScript ์ถ๊ฐ ( Adding TypeScript)
2424
25- You can learn how to do this in our [ installation page ] ( / download) .
25+ [ ์ค์น ํ์ด์ง ] ( https://www.typescriptlang.org/ download) ์์ ๋ฐฉ๋ฒ์ ํ์ธํ ์ ์์ต๋๋ค .
2626
2727### TSConfig
2828
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+ ์์ ๊ฐ์ ๊ฒฝ์ฐ, ๋ค์๊ณผ ๊ฐ์ ํ์ผ์ด ํ์ํฉ๋๋ค :
3131
3232``` json5
3333{
34- // Change this to match your project
34+ // ํ๋ก์ ํธ์ ์๋ง๊ฒ ์์ ํ์ธ์.
3535 include: [" src/**/*" ],
3636
3737 compilerOptions: {
38- // Tells TypeScript to read JS files, as
39- // normally they are ignored as source files
38+ // ์ผ๋ฐ์ ์ผ๋ก ์์ค ํ์ผ๋ก ๋ฌด์๋๊ธฐ ๋๋ฌธ์,
39+ // TypeScript๊ฐ JS ํ์ผ์ ์ฝ๋๋ก ์ง์ํฉ๋๋ค.
4040 allowJs: true ,
41- // Generate d.ts files
41+ // d.ts ํ์ผ์ ์์ฑ์ํต๋๋ค.
4242 declaration: true ,
43- // This compiler run should
44- // only output d.ts files
43+ // ์ปดํ์ผ๋ฌ ์คํ์ด ์ค์ง
44+ // d.ts ํ์ผ๋ง ์ถ๋ ฅํ๊ฒ ํฉ๋๋ค.
4545 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 ํ์ผ ์์ ์์ฑ๋ฉ๋๋ค.
4949 outDir: " dist" ,
5050 },
5151}
5252```
5353
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๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค .
5656
5757``` sh
5858npx typescript src/** /* .js --declaration --allowJs --emitDeclarationOnly --outDir types
5959```
6060
61- ## Run the compiler
61+ ## ์ปดํ์ผ๋ฌ ์คํ ( Run the compiler)
6262
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 ` ์ ํ์ผ์ด ์์ ๋, ์ด๋ฌํ ํ์ผ๋ค์ด ํจํค์ง์ ํฌํจ๋์ด ์๋์ง ํ์ธํฉ๋๋ค .
6565
66- ## Editing the package.json
66+ ## package.json ์์ ( Editing the package.json)
6767
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 ` ๋ฅผ ํ์ธํฉ๋๋ค .
7070
71- | Package.json | Location of default .d.ts |
71+ | Package.json | ๊ธฐ๋ณธ .d.ts์ ์์น |
7272| :------------------------ | :----------------------------- |
73- | No "types" field | checks "main", then index.d.ts |
73+ | "types" ํ๋ ์์ | "main" ํ์ธ ํ, index.d.ts ํ์ธ |
7474| "types": "main.d.ts" | main.d.ts |
7575| "types": "./dist/main.js" | ./main/main.d.ts |
7676
77- If absent, then "main" is used
77+ type ํ๋๊ฐ ์๋ค๋ฉด, "main"์ผ๋ก ๋์ด๊ฐ๋๋ค.
7878
79- | Package.json | Location of default .d.ts |
79+ | Package.json | ๊ธฐ๋ณธ .d.ts์ ์์น |
8080| :----------------------- | :------------------------ |
81- | No "main" field | index.d.ts |
81+ | "main" ํ๋ ์์ | index.d.ts |
8282| "main":"index.js" | index.d.ts |
8383| "main":"./dist/index.js" | ./dist/index.d.ts |
8484
85- ## Tips
85+ ## ํ ( Tips)
8686
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