Skip to content

Commit f57223d

Browse files
committed
translate files into ja
1 parent d7a1366 commit f57223d

File tree

4 files changed

+280
-280
lines changed

4 files changed

+280
-280
lines changed
Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
11
---
2-
title: Creating .d.ts Files from .js files
2+
title: .jsファイルから.d.tsファイルを生成する
33
layout: docs
4-
permalink: /docs/handbook/declaration-files/dts-from-js.html
5-
oneline: "How to add d.ts generation to JavaScript projects"
4+
permalink: /ja/docs/handbook/declaration-files/dts-from-js.html
5+
oneline: "JavaScriptプロジェクトでd.tsファイルを生成する方法"
66
translatable: true
77
---
88

9-
[With TypeScript 3.7](/docs/handbook/release-notes/typescript-3-7.html#--declaration-and---allowjs),
10-
TypeScript added support for generating .d.ts files from JavaScript using JSDoc syntax.
9+
[TypeScript 3.7](/docs/handbook/release-notes/typescript-3-7.html#--declaration-and---allowjs)では、
10+
TypeScriptに、JSDoc構文を使ったJavaScriptから.d.tsファイルを生成するためのサポートが導入されました。
1111

12-
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.
13-
TypeScript supports most JSDoc tags, you can find [the reference here](/docs/handbook/type-checking-javascript-files.html#supported-jsdoc).
12+
この仕組みは、プロジェクトをTypeScriptに移行することなく、TypeScriptが備わったエディタの経験を自分のものにできるということを意味します。
13+
TypeScriptはほとんどのJSDocタグをサポートしています。リファレンスは[こちら](/docs/handbook/type-checking-javascript-files.html#supported-jsdoc)
1414

15-
## Setting up your Project to emit .d.ts files
15+
## .d.tsファイルを出力するようにプロジェクトを設定する
1616

17-
To add creation of .d.ts files in your project, you will need to do up-to four steps:
17+
プロジェクトに.d.tsファイルの作成を追加するように設定するには、最大4つのステップを実行する必要があります:
1818

19-
- Add TypeScript to your dev dependencies
20-
- Add a `tsconfig.json` to configure TypeScript
21-
- Run the TypeScript compiler to generate the corresponding d.ts files for JS files
22-
- (optional) Edit your package.json to reference the types
19+
- dev dependenciesにTypeScriptを追加する
20+
- TypeScriptを設定するための`tsconfig.json`を追加する
21+
- TypeScriptコンパイラを実行して、JSファイルに対応するd.tsファイルを生成する
22+
- (オプション) package.jsonを編集して型を参照できるようにする
2323

24-
### Adding TypeScript
24+
### TypeScriptを追加する
2525

26-
You can learn how to do this in our [installation page](/download).
26+
こちらは、[インストールページ](/download)を参照してください。
2727

2828
### TSConfig
2929

30-
The TSConfig is a jsonc file which configures both your compiler flags, and declare where to find files.
31-
In this case, you will want a file like the following:
30+
TSConfigはコンパイラのフラグを設定し、対象のファイルを宣言するためのjsoncファイルです。
31+
今回のケースでは、次のようなファイルが必要になるでしょう:
3232

3333
```json5
3434
{
35-
// Change this to match your project
35+
// プロジェクトに合わせて変更してください
3636
include: ["src/**/*"],
3737

3838
compilerOptions: {
39-
// Tells TypeScript to read JS files, as
40-
// normally they are ignored as source files
39+
// JSファイルは通常はソースファイルとしては無視されますが、
40+
// ここではJSファイルを読み込むようにTypeScriptに指示します
4141
allowJs: true,
42-
// Generate d.ts files
42+
// d.tsファイルを生成します
4343
declaration: true,
44-
// This compiler run should
45-
// only output d.ts files
44+
// コンパイラを実行すると
45+
// d.tsファイルのみ出力されます
4646
emitDeclarationOnly: true,
47-
// Types should go into this directory.
48-
// Removing this would place the .d.ts files
49-
// next to the .js files
47+
// 型はこのディレクトリに出力されます
48+
// このオプションを削除すると
49+
// .jsファイルの隣に.d.tsファイルが置かれます
5050
outDir: "dist",
5151
},
5252
}
5353
```
5454

55-
You can learn more about the options in the [tsconfig reference](/reference).
56-
An alternative to using a TSConfig file is the CLI, this is the same behavior as a CLI command.
55+
オプションについては、[tsconfigリファレンス](/reference)で詳しく知ることができます。
56+
TSConfigファイルを使用する代替手段としてCLIがあります。次は上記のTSConfigファイルと同じふるまいをするCLIコマンドです。
5757

5858
```sh
5959
npx typescript src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir types
6060
```
6161

62-
## Run the compiler
62+
## コンパイラを実行する
6363

64-
You can learn how to do this in our [installation page](/download).
65-
You want to make sure these files are included in your package if you have the files in your project's `.gitignore`.
64+
実行方法については[インストールページ](/download)を参照してください。
65+
プロジェクトの`.gitignore`に生成されたファイルがある場合は、確実にパッケージにそれらのファイルが含まれるようにしてください。
6666

67-
## Editing the package.json
67+
## package.jsonを編集する
6868

69-
TypeScript replicates the node resolution for modules in a `package.json`, with an additional step for finding .d.ts files.
70-
Roughly, the resolution will first check the optional `"types"` field, then the `"main"` field, and finally will try `index.d.ts` in the root.
69+
TypeScriptは、`package.json`の中でNodeのモジュール解決を再現し、.d.tsファイルを見つけるためのステップを追加します。
70+
大まかには、ノード解決はオプションである`"types"`フィールドをチェックし、次に`"main"`フィールド、そして最後にルートの`index.d.ts`を試します。
7171

72-
| Package.json | Location of default .d.ts |
72+
| Package.json | デフォルトの.d.tsの場所 |
7373
| :------------------------ | :----------------------------- |
74-
| No "types" field | checks "main", then index.d.ts |
74+
| "types"フィールドがない | "main"をチェックし、次にindex.d.ts|
7575
| "types": "main.d.ts" | main.d.ts |
7676
| "types": "./dist/main.js" | ./main/main.d.ts |
7777

78-
If absent, then "main" is used
78+
もし存在しなければ、次は"main"が使用されます
7979

80-
| Package.json | Location of default .d.ts |
80+
| Package.json | デフォルトの.d.tsの場所 |
8181
| :----------------------- | :------------------------ |
82-
| No "main" field | index.d.ts |
82+
| "main"フィールドがない | index.d.ts |
8383
| "main":"index.js" | index.d.ts |
8484
| "main":"./dist/index.js" | ./dist/index.d.ts |
8585

8686
## Tips
8787

88-
If you'd like to write tests for your .d.ts files, try [tsd](https://github.com/SamVerschueren/tsd).
88+
.d.tsファイルにテストを記述したいなら、[tsd](https://github.com/SamVerschueren/tsd)を試してみてください。
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
---
2-
title: JS Projects Utilizing TypeScript
2+
title: TypeScriptを活用したJSプロジェクト
33
layout: docs
4-
permalink: /docs/handbook/intro-to-js-ts.html
5-
oneline: How to add type checking to JavaScript files using TypeScript
4+
permalink: /ja/docs/handbook/intro-to-js-ts.html
5+
oneline: TypeScriptを使ってJavaScriptファイルに型チェックを追加する方法
66
translatable: true
77
---
88

9-
The type system in TypeScript has different levels of strictness when working with a codebase:
9+
TypeScriptの型システムがコードベースを扱う際には、様々な厳密さのレベルがあります:
1010

11-
- A type-system based only on inference with JavaScript code
12-
- Incremental typing in JavaScript [via JSDoc](/docs/handbook/jsdoc-supported-types.html)
13-
- Using `// @ts-check` in a JavaScript file
14-
- TypeScript code
15-
- TypeScript with [`strict`](/tsconfig#strict) enabled
11+
- JavaScriptのコードを使った推論のみに基づく型システム
12+
- [JSDoc](/docs/handbook/jsdoc-supported-types.html)によるJavaScriptの段階的な型付け
13+
- JavaScriptファイルにおける`// @ts-check`の使用
14+
- TypeScriptコード
15+
- [`strict`](/tsconfig#strict)を有効にしたTypeScript
1616

17-
Each step represents a move towards a safer type-system, but not every project needs that level of verification.
17+
それぞれのステップはより安全な型システムへの動きを表していますが、すべてのプロジェクトがそのレベルでの検証を必要としているわけではありません。
1818

19-
## TypeScript with JavaScript
19+
## JavaScriptと併用するTypeScript
2020

21-
This is when you use an editor which uses TypeScript to provide tooling like auto-complete, jump to symbol and refactoring tools like rename.
22-
The [homepage](/) has a list of editors which have TypeScript plugins.
21+
こちらは、オートコンプリートやシンボルへのジャンプといった機能や、リネームなどのリファクタリングツールを提供するためにTypeScriptを使用しているエディタを使う場合です。
22+
[homepage](/)では、TypeScriptプラグインを備えているエディタをリストしています。
2323

24-
## Providing Type Hints in JS via JSDoc
24+
## JSDocを使ってJSで型ヒントを提供する
2525

26-
In a `.js` file, types can often be inferred. When types can't be inferred, they can be specified using JSDoc syntax.
26+
`.js`ファイルでは、多くの場合型を推測することが可能です。型が推測できない場合、JSDoc構文を使って指定することができます。
2727

28-
JSDoc annotations come before a declaration will be used to set the type of that declaration. For example:
28+
宣言の前でJSDocのアノテーションを使い、その宣言の型を設定します。例えば:
2929

3030
```js twoslash
3131
/** @type {number} */
@@ -35,12 +35,12 @@ x = 0; // OK
3535
x = false; // OK?!
3636
```
3737

38-
You can find the full list of supported JSDoc patterns [in JSDoc Supported Types](/docs/handbook/jsdoc-supported-types.html).
38+
サポートしているJSDocパターンの全リストは[JSDocがサポートする型](/docs/handbook/jsdoc-supported-types.html)にあります。
3939

4040
## `@ts-check`
4141

42-
The last line of the previous code sample would raise an error in TypeScript, but it doesn't by default in a JS project.
43-
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.
42+
前述のコードサンプルの最後の行はTypeScriptではエラーとなりますが、JSプロジェクトではデフォルトではエラーを発生させません。
43+
JavaScriptファイルでエラーを有効化するには、`.js`ファイルの最初の行に`// @ts-check`を追加して、TypeScriptのエラーを発生させるようにします。
4444

4545
```js twoslash
4646
// @ts-check
@@ -49,13 +49,13 @@ To enable errors in your JavaScript files add: `// @ts-check` to the first line
4949
var x;
5050

5151
x = 0; // OK
52-
x = false; // Not OK
52+
x = false; // エラー
5353
```
5454

55-
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).
56-
You can skip checking some files by adding a `// @ts-nocheck` comment to files.
55+
エラーを追加したいJavaScriptファイルがたくさんある場合は、[`jsconfig.json`](/docs/handbook/tsconfig-json.html)を使用するように変更しましょう。
56+
ファイルに`// @ts-nocheck`コメントをつけることで、ファイルのチェックを省略することができます。
5757

58-
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.
58+
TypeScriptはあなたが納得できないようなエラーを発生させるかもしれませんが、その場合は前の行に`// @ts-ignore`または`// @ts-expect-error`を追加することで、特定の行のエラーを無視することができます。
5959

6060
```js twoslash
6161
// @ts-check
@@ -64,7 +64,7 @@ var x;
6464

6565
x = 0; // OK
6666
// @ts-expect-error
67-
x = false; // Not OK
67+
x = false; // エラー
6868
```
6969

70-
To learn more about how JavaScript is interpreted by TypeScript read [How TS Type Checks JS](/docs/handbook/type-checking-javascript-files.html)
70+
JavaScriptがTypeScriptによってどのように解釈されるかについて知りたい場合は、[TSの型がJSをチェックする方法](/docs/handbook/type-checking-javascript-files.html)を参照してください。

0 commit comments

Comments
 (0)