Skip to content

Commit 38b87bf

Browse files
committed
docs: translate typescript support
1 parent 80f3301 commit 38b87bf

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/guide/typescript-support.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
より詳細を知るためには、[TypeScript compiler options docs](https://www.typescriptlang.org/docs/handbook/compiler-options.html) を参照してください。
2828

29-
## Webpack Configuration
29+
## Webpack の設定
3030

31-
If you are using a custom Webpack configuration `ts-loader` needs to be configured to parse `<script lang="ts">` blocks in `.vue` files:
31+
カスタムの Webpack の設定を使っている場合、 `.vue` ファイルの `<script lang="ts">` ブロックをパースするように `ts-loader` を設定する必要があります:
3232

3333
```js{10}
3434
// webpack.config.js
@@ -76,7 +76,7 @@ vue add typescript
7676
</script>
7777
```
7878

79-
Or, if you want to combine TypeScript with a [JSX `render` function](/guide/render-function.html#jsx):
79+
また、TypeScript [JSX `render` 関数](/guide/render-function.html#jsx) を組み合わせたい場合:
8080

8181
```html
8282
<script lang="tsx">
@@ -102,7 +102,7 @@ const Component = defineComponent({
102102
})
103103
```
104104

105-
If you're using [single-file components](/guide/single-file-component.html) then this would typically be written as:
105+
[単一ファイルコンポーネント](/guide/single-file-component.html) を使っている場合、これは一般的に次のように書かれます:
106106

107107
```vue
108108
<script lang="ts">
@@ -153,30 +153,30 @@ const Component = defineComponent({
153153
})
154154
```
155155

156-
### Augmenting Types for `globalProperties`
156+
### `globalProperties` のための型の拡張
157157

158-
Vue 3 provides a [`globalProperties` object](../api/application-config.html#globalproperties) that can be used to add a global property that can be accessed in any component instance. For example, a [plugin](./plugins.html#writing-a-plugin) might want to inject a shared global object or function.
158+
Vue 3 には [`globalProperties` オブジェクト](../api/application-config.html#globalproperties) が用意されていて、任意のコンポーネントインスタンスからアクセス可能なグローバルプロパティを追加するために使用できます。例えば、 [プラグイン](./plugins.html#プラグインを書く) では共有されたグローバルオブジェクトや関数を注入したい場合があります。
159159

160160
```ts
161-
// User Definition
161+
// ユーザの定義
162162
import axios from 'axios'
163163

164164
const app = Vue.createApp({})
165165
app.config.globalProperties.$http = axios
166166

167-
// Plugin for validating some data
167+
// あるデータを検証するためのプラグイン
168168
export default {
169169
install(app, options) {
170170
app.config.globalProperties.$validate = (data: object, rule: object) => {
171-
// check whether the object meets certain rules
171+
// 対象のデータが特定のルールを満たしているかチェック
172172
}
173173
}
174174
}
175175
```
176176

177-
In order to tell TypeScript about these new properties, we can use [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation).
177+
これらの新しいプロパティを TypeScript に伝えるために、[Module Augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) を使うことができます。
178178

179-
In the above example, we could add the following type declaration:
179+
上記の例では、次のような型宣言を追加することができます:
180180

181181
```ts
182182
import axios from 'axios'
@@ -189,15 +189,15 @@ declare module '@vue/runtime-core' {
189189
}
190190
```
191191

192-
We can put this type declaration in the same file, or in a project-wide `*.d.ts` file (for example, in the `src/typings` folder that is automatically loaded by TypeScript). For library/plugin authors, this file should be specified in the `types` property in `package.json`.
192+
この型宣言は同じファイル、またはプロジェクト全体の `*.d.ts` ファイル(例えば、 TypeScript で自動的に読み込まれる `src/typings` フォルダの中)に記述することができます。ライブラリやプラグインの作者は、このファイルを `package.json``types` プロパティで指定します。
193193

194-
::: warning Make sure the declaration file is a TypeScript module
195-
In order to take advantage of module augmentation, you will need to ensure there is at least one top-level `import` or `export` in your file, even if it is just `export {}`.
194+
::: warning 宣言ファイルが TypeScript モジュールであることを確認
195+
Module Augmentation を利用するためには、ファイルの中に少なくとも1つのトップレベルの `import` `export` があることを確認する必要があります。それが単に `export {}` であってもです。
196196

197-
[In TypeScript](https://www.typescriptlang.org/docs/handbook/modules.html), any file containing a top-level `import` or `export` is considered a 'module'. If type declaration is made outside of a module, it will overwrite the original types rather than augmenting them.
197+
[TypeScript](https://www.typescriptlang.org/docs/handbook/modules.html) では、トップレベルの `import` `export` を含むファイルはすべて「モジュール」とみなされます。モジュールの外で型宣言が行われた場合、元の型を拡張するのではなく、上書きしてしまいます。
198198
:::
199199

200-
For more information about the `ComponentCustomProperties` type, see its [definition in `@vue/runtime-core`](https://github.com/vuejs/vue-next/blob/2587f36fe311359e2e34f40e8e47d2eebfab7f42/packages/runtime-core/src/componentOptions.ts#L64-L80) and [the TypeScript unit tests](https://github.com/vuejs/vue-next/blob/master/test-dts/componentTypeExtensions.test-d.tsx) to learn more.
200+
`ComponentCustomProperties` 型について詳しくは、[`@vue/runtime-core` での定義](https://github.com/vuejs/vue-next/blob/2587f36fe311359e2e34f40e8e47d2eebfab7f42/packages/runtime-core/src/componentOptions.ts#L64-L80) と、[TypeScript ユニットテスト](https://github.com/vuejs/vue-next/blob/master/test-dts/componentTypeExtensions.test-d.tsx) を参照してください。
201201

202202
### 戻り値の型にアノテーションをつける
203203

@@ -260,8 +260,7 @@ const Component = defineComponent({
260260
```
261261

262262
::: warning
263-
Because of a [design limitation](https://github.com/microsoft/TypeScript/issues/38845) in TypeScript when it comes
264-
to type inference of function expressions, you have to be careful with `validators` and `default` values for objects and arrays:
263+
TypeScript には、関数式の型推論に [設計上の制限](https://github.com/microsoft/TypeScript/issues/38845) があるため、 `validators` と、オブジェクトや配列の `default` 値に注意する必要があります:
265264
:::
266265

267266
```ts
@@ -276,15 +275,15 @@ const Component = defineComponent({
276275
props: {
277276
bookA: {
278277
type: Object as PropType<Book>,
279-
// Make sure to use arrow functions
278+
// 必ずアロー関数を使うこと
280279
default: () => ({
281280
title: 'Arrow Function Expression'
282281
}),
283282
validator: (book: Book) => !!book.title
284283
},
285284
bookB: {
286285
type: Object as PropType<Book>,
287-
// Or provide an explicit this parameter
286+
// または明示的にこのパラメータを提供する
288287
default(this: void) {
289288
return {
290289
title: 'Function Expression'
@@ -298,25 +297,25 @@ const Component = defineComponent({
298297
})
299298
```
300299

301-
### Annotating emits
300+
### アノテーション emits
302301

303-
We can annotate a payload for the emitted event. Also, all non-declared emitted events will throw a type error when called:
302+
発行されたイベントのペイロードにアノテーションをつけることができます。また、すべての宣言されていない発行されたイベントは、呼び出されたときに型エラーが発生します:
304303

305304
```ts
306305
const Component = defineComponent({
307306
emits: {
308307
addBook(payload: { bookName: string }) {
309-
// perform runtime validation
308+
// ランタイムバリデーションの実行
310309
return payload.bookName.length > 0
311310
}
312311
},
313312
methods: {
314313
onSubmit() {
315314
this.$emit('addBook', {
316-
bookName: 123 // Type error!
315+
bookName: 123 // 型エラー!
317316
})
318317

319-
this.$emit('non-declared-event') // Type error!
318+
this.$emit('non-declared-event') // 型エラー!
320319
}
321320
}
322321
})

0 commit comments

Comments
 (0)