Skip to content

Commit ecb4e62

Browse files
authored
DTS ๋ฒˆ์—ญ (#151)
* DTS ๋ฒˆ์—ญ ์ผ๋ถ€ ์™„๋ฃŒ in #121 * ๋ฆฌ๋ทฐ ๋‚ด์šฉ์— ๋งž์ถ”์–ด์„œ ์ˆ˜์ • ๋ฐ ์ถ”๊ฐ€ ๋ฒˆ์—ญ in #121 * ๋ฆฌ๋ทฐ์— ๋งž์ถ”์–ด์„œ ๋ฒˆ์—ญ ์ˆ˜์ • in #121 * ๋„์–ด์“ฐ๊ธฐ ๊ด€๋ จ ๋ฒˆ์—ญ ์ˆ˜์ • in #121
1 parent a005641 commit ecb4e62

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

โ€Žpages/declaration-files/creating-dts-files-from-js.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,83 +5,83 @@ permalink: /docs/handbook/declaration-files/dts-from-js.html
55
oneline: "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
5858
npx 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

Comments
ย (0)