1
1
---
2
- title : Declaration Reference
2
+ title : 宣言リファレンス
3
3
layout : docs
4
- permalink : /docs/handbook/declaration-files/by-example.html
5
- oneline : " How to create a d.ts file for a module "
4
+ permalink : /ja/ docs/handbook/declaration-files/by-example.html
5
+ oneline : " モジュール用の.d.tsファイルの作り方 "
6
6
---
7
7
8
- The purpose of this guide is to teach you how to write a high-quality definition file.
9
- This guide is structured by showing documentation for some API, along with sample usage of that API,
10
- and explaining how to write the corresponding declaration.
8
+ 本ガイドの目的は、すぐれた宣言ファイルの書き方を示すことです。
9
+ 本ガイドは、ある API の仕様と、その API の使い方の例示で構成されており、
10
+ それに対応する宣言の記述方法について解説しています。
11
11
12
- These examples are ordered in approximately increasing order of complexity.
12
+ 以下のサンプルは、複雑度がほぼ高い順に並んでいます。
13
13
14
- ## Objects with Properties
14
+ ## プロパティを持つオブジェクト
15
15
16
- _ Documentation _
16
+ _ 仕様 _
17
17
18
- > The global variable ` myLib ` has a function ` makeGreeting ` for creating greetings,
19
- > and a property ` numberOfGreetings ` indicating the number of greetings made so far.
18
+ > グローバス変数 ` myLib ` は、挨拶を作る ` makeGreeting ` 関数と、
19
+ > これまで作られた挨拶の数を示すプロパティ ` numberOfGreetings ` を持っています。
20
20
21
- _ Code _
21
+ _ コード例 _
22
22
23
23
``` ts
24
24
let result = myLib .makeGreeting (" hello, world" );
@@ -27,9 +27,9 @@ console.log("The computed greeting is:" + result);
27
27
let count = myLib .numberOfGreetings ;
28
28
```
29
29
30
- _ Declaration _
30
+ _ 宣言 _
31
31
32
- Use ` declare namespace ` to describe types or values accessed by dotted notation.
32
+ ドット記法でアクセス可能な型や値を記述するには、 ` declare namespace ` を使います。
33
33
34
34
``` ts
35
35
declare namespace myLib {
@@ -38,52 +38,52 @@ declare namespace myLib {
38
38
}
39
39
```
40
40
41
- ## Overloaded Functions
41
+ ## オーバーロードされた関数
42
42
43
- _ Documentation _
43
+ _ 仕様 _
44
44
45
- The ` getWidget ` function accepts a number and returns a Widget, or accepts a string and returns a Widget array.
45
+ ` getWidget ` 関数は、数値を受け取って Widget を返したり、あるいは文字列を受け取って Widget の配列を返します。
46
46
47
- _ Code _
47
+ _ コード例 _
48
48
49
49
``` ts
50
50
let x: Widget = getWidget (43 );
51
51
52
52
let arr: Widget [] = getWidget (" all of them" );
53
53
```
54
54
55
- _ Declaration _
55
+ _ 宣言 _
56
56
57
57
``` ts
58
58
declare function getWidget(n : number ): Widget ;
59
59
declare function getWidget(s : string ): Widget [];
60
60
```
61
61
62
- ## Reusable Types (Interfaces )
62
+ ## 再利用可能な型 (インターフェース )
63
63
64
- _ Documentation _
64
+ _ 仕様 _
65
65
66
- > When specifying a greeting, you must pass a ` GreetingSettings ` object.
67
- > This object has the following properties :
66
+ > ` GreetingSettings ` オブジェクトを渡して、挨拶を指定します。
67
+ > このオブジェクトは次のようなプロパティを持っています :
68
68
>
69
- > 1 - greeting: Mandatory string
69
+ > 1 - greeting: 必須の文字列
70
70
>
71
- > 2 - duration: Optional length of time (in milliseconds )
71
+ > 2 - duration: 任意の時間の長さ (ミリ秒単位 )
72
72
>
73
- > 3 - color: Optional string, e.g. '#ff00ff'
73
+ > 3 - color: 任意の文字列 (例: '#ff00ff')
74
74
75
- _ Code _
75
+ _ コード例 _
76
76
77
77
``` ts
78
78
greet ({
79
79
greeting: " hello world" ,
80
- duration: 4000
80
+ duration: 4000 ,
81
81
});
82
82
```
83
83
84
- _ Declaration _
84
+ _ 宣言 _
85
85
86
- Use an ` interface ` to define a type with properties.
86
+ ` interface ` を使用して、プロパティを持つ型を定義します。
87
87
88
88
``` ts
89
89
interface GreetingSettings {
@@ -95,13 +95,13 @@ interface GreetingSettings {
95
95
declare function greet(setting : GreetingSettings ): void ;
96
96
```
97
97
98
- ## Reusable Types (Type Aliases )
98
+ ## 再利用可能な型 (タイプエイリアス )
99
99
100
- _ Documentation _
100
+ _ 仕様 _
101
101
102
- > Anywhere a greeting is expected, you can provide a ` string ` , a function returning a ` string ` , or a ` Greeter ` instance.
102
+ > 挨拶が期待される場所に対して、 ` string ` 、 ` string ` を返す関数、あるいは ` Greeter ` インスタンスを与えることができます。
103
103
104
- _ Code _
104
+ _ コード例 _
105
105
106
106
``` ts
107
107
function getGreeting() {
@@ -114,34 +114,34 @@ greet(getGreeting);
114
114
greet (new MyGreeter ());
115
115
```
116
116
117
- _ Declaration _
117
+ _ 宣言 _
118
118
119
- You can use a type alias to make a shorthand for a type :
119
+ 型の省略表現を作るために、タイプエイリアスを使うことができます :
120
120
121
121
``` ts
122
122
type GreetingLike = string | (() => string ) | MyGreeter ;
123
123
124
124
declare function greet(g : GreetingLike ): void ;
125
125
```
126
126
127
- ## Organizing Types
127
+ ## 型の整理
128
128
129
- _ Documentation _
129
+ _ 仕様 _
130
130
131
- > The ` greeter ` object can log to a file or display an alert.
132
- > You can provide LogOptions to ` .log(...) ` and alert options to ` .alert(...) `
131
+ > ` greeter ` オブジェクトは、ファイルにログを記録したり、アラートを表示したりすることができます。
132
+ > ログオプションは ` .log(...) ` に、アラートオプションは ` .alert(...) ` に与えることができます。
133
133
134
- _ Code _
134
+ _ コード例 _
135
135
136
136
``` ts
137
137
const g = new Greeter (" Hello" );
138
138
g .log ({ verbose: true });
139
139
g .alert ({ modal: false , title: " Current Greeting" });
140
140
```
141
141
142
- _ Declaration _
142
+ _ 宣言 _
143
143
144
- Use namespaces to organize types.
144
+ 名前空間を使って型を整理します。
145
145
146
146
``` ts
147
147
declare namespace GreetingLib {
@@ -156,11 +156,11 @@ declare namespace GreetingLib {
156
156
}
157
157
```
158
158
159
- You can also create nested namespaces in one declaration:
159
+ 宣言でネストした名前空間を作ることもできます:
160
160
161
161
``` ts
162
162
declare namespace GreetingLib .Options {
163
- // Refer to via GreetingLib.Options.Log
163
+ // GreetingLib.Options.Logで参照します
164
164
interface Log {
165
165
verbose? : boolean ;
166
166
}
@@ -172,13 +172,13 @@ declare namespace GreetingLib.Options {
172
172
}
173
173
```
174
174
175
- ## Classes
175
+ ## クラス
176
176
177
- _ Documentation _
177
+ _ 仕様 _
178
178
179
- > You can create a greeter by instantiating the ` Greeter ` object, or create a customized greeter by extending from it.
179
+ > ` Greeter ` オブジェクトをインスタンス化して greeter を作成したり、それを拡張してカスタマイズした greeter を作成することができます。
180
180
181
- _ Code _
181
+ _ コード例 _
182
182
183
183
``` ts
184
184
const myGreeter = new Greeter (" hello, world" );
@@ -192,10 +192,10 @@ class SpecialGreeter extends Greeter {
192
192
}
193
193
```
194
194
195
- _ Declaration _
195
+ _ 宣言 _
196
196
197
- Use ` declare class ` to describe a class or class-like object.
198
- Classes can have properties and methods as well as a constructor.
197
+ クラスやクラスライクなオブジェクトを記述するには、 ` declare class ` を使います。
198
+ クラスはコンストラクタだけではなく、プロパティやメソッドを持つことができます。
199
199
200
200
``` ts
201
201
declare class Greeter {
@@ -206,46 +206,45 @@ declare class Greeter {
206
206
}
207
207
```
208
208
209
- ## Global Variables
209
+ ## グローバル変数
210
210
211
- _ Documentation _
211
+ _ 仕様 _
212
212
213
- > The global variable ` foo ` contains the number of widgets present.
213
+ > グローバル変数 ` foo ` には、存在する widget の数が格納されています。
214
214
215
- _ Code _
215
+ _ コード例 _
216
216
217
217
``` ts
218
218
console .log (" Half the number of widgets is " + foo / 2 );
219
219
```
220
220
221
- _ Declaration _
221
+ _ 宣言 _
222
222
223
- Use ` declare var ` to declare variables.
224
- If the variable is read-only, you can use ` declare const ` .
225
- You can also use ` declare let ` if the variable is block-scoped.
223
+ 変数を宣言するには、 ` declare var ` を使います。
224
+ 変数が読み取り専用の場合には、 ` declare const ` を使用することができます。
225
+ また、変数がブロックスコープに制限される場合は、 ` declare let ` を使うこともできます。
226
226
227
227
``` ts
228
- /** The number of widgets present */
228
+ /** 存在する widget の数 */
229
229
declare var foo: number ;
230
230
```
231
231
232
- ## Global Functions
232
+ ## グローバル関数
233
233
234
- _ Documentation _
234
+ _ 仕様 _
235
235
236
- > You can call the function ` greet ` with a string to show a greeting to the user.
236
+ > 文字列を与えて関数 ` greet ` を呼び出すと、ユーザーに挨拶を表示することができます。
237
237
238
- _ Code _
238
+ _ コード例 _
239
239
240
240
``` ts
241
241
greet (" hello, world" );
242
242
```
243
243
244
- _ Declaration _
244
+ _ 宣言 _
245
245
246
- Use ` declare function ` to declare functions.
246
+ 関数を宣言するには、 ` declare function ` を使用します。
247
247
248
248
``` ts
249
249
declare function greet(greeting : string ): void ;
250
250
```
251
-
0 commit comments