Skip to content

Commit 66a9801

Browse files
authored
Tooling > TypeScript Support (#53)
* feat: translate typescript support page into japanese * fix: apply feedback
1 parent 6f7cf84 commit 66a9801

File tree

1 file changed

+51
-47
lines changed

1 file changed

+51
-47
lines changed

src/guide/typescript-support.md

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
1-
# TypeScript Support
1+
# TypeScript のサポート
22

3-
> [Vue CLI](https://cli.vuejs.org) provides built-in TypeScript tooling support.
3+
> [Vue CLI](https://cli.vuejs.org) は、ビルトインの TypeScript ツールサポートを提供します。
44
5-
## Official Declaration in NPM Packages
5+
## NPM パッケージ内の公式型宣言
66

7-
A static type system can help prevent many potential runtime errors as applications grow, which is why Vue 3 is written in TypeScript. This means you don't need any additional tooling to use TypeScript with Vue - it has a first-class citizen support.
7+
静的型システムは、特にアプリケーションが成長するに伴い、多くの潜在的なランタイムエラーを防止するのに役立ち、これが Vue 3 TypeScript で書かれている理由です。このことは、あなたが Vue 3 とともに TypeScript を使うために追加のツールを必要としないことを意味します - それは第一級市民 (first-class citizen) としてサポートを受けられます。
88

9-
## Recommended Configuration
9+
## 推奨される構成
1010

1111
```js
1212
// tsconfig.json
1313
{
1414
"compilerOptions": {
1515
"target": "esnext",
1616
"module": "esnext",
17-
// this enables stricter inference for data properties on `this`
17+
// これは `this` のデータプロパティに対してより厳密な推論を可能にします
1818
"strict": true,
1919
"jsx": "preserve",
2020
"moduleResolution": "node"
2121
}
2222
}
2323
```
2424

25-
Note that you have to include `strict: true` (or at least `noImplicitThis: true` which is a part of `strict` flag) to leverage type checking of `this` in component methods otherwise it is always treated as `any` type.
25+
コンポーネントメソッドにおける `this` の型チェックを活用するために `strict: true` (もしくは少なくとも `strict` フラグの一部である `noImplicitThis: true`) を含める必要があることに注意してください。そうでないと、`this` は常に `any` 型として扱われます。
2626

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

29-
## Development Tooling
29+
## 開発ツール
3030

31-
### Project Creation
31+
### プロジェクトの作成
3232

33-
[Vue CLI](https://github.com/vuejs/vue-cli) can generate new projects that use TypeScript. To get started:
33+
[Vue CLI](https://github.com/vuejs/vue-cli) は、TypeSript を使った新しいプロジェクトを作成できます。はじめるためには:
3434

3535
```bash
36-
# 1. Install Vue CLI, if it's not already installed
36+
# 1. Vue CLI をまだインストールしていなければ、インストールします
3737
npm install --global @vue/cli@next
3838

39-
# 2. Create a new project, then choose the "Manually select features" option
39+
# 2. 新しいプロジェクトを作成し、"Manually select features" を選択してください
4040
vue create my-project-name
4141

42-
# If you already have a Vue CLI project without TypeScript, please add a proper Vue CLI plugin:
42+
# もしすでに TypeScript をもたない Vue CLI で作成したプロジェクトがある場合、適切な Vue CLI プラグインを追加してください:
4343
vue add typescript
4444
```
4545

46-
Make sure that `script` part of the component has TypeScript set as a language:
46+
コンポーネントの `script` の部分に言語として TypeScript が設定されていることを確認してください:
4747

4848
```html
4949
<script lang="ts">
5050
...
5151
</script>
5252
```
5353

54-
### Editor Support
54+
### エディタによるサポート
5555

56-
For developing Vue applications with TypeScript, we strongly recommend using [Visual Studio Code](https://code.visualstudio.com/), which provides great out-of-the-box support for TypeScript. If you are using [single-file components](./single-file-components.html) (SFCs), get the awesome [Vetur extension](https://github.com/vuejs/vetur), which provides TypeScript inference inside SFCs and many other great features.
56+
TypeScript による Vue アプリケーションの開発のために、すぐに利用できる TypeScript サポートを提供している [Visual Studio Code](https://code.visualstudio.com/) を強く推奨します。[単一ファイルコンポーネント](./single-file-components.html) (SFCs) を使用している場合、SFC 内部での TypeScript の推論やその他の優れた機能を提供している、素晴らしい [Vetur エクステンション](https://github.com/vuejs/vetur) を入手してください。
5757

58-
[WebStorm](https://www.jetbrains.com/webstorm/) also provides out-of-the-box support for both TypeScript and Vue.
58+
[WebStorm](https://www.jetbrains.com/webstorm/) もすぐに利用できる TypeScript Vue のサポートを提供しています。
5959

60-
## Defining Vue components
60+
## Vue コンポーネントを定義する
6161

62-
To let TypeScript properly infer types inside Vue component options, you need to define components with `defineComponent` global method:
62+
TypeScript Vue コンポーネントオブションのなかで適切に型を推論させるために、`defineComponent` グローバルメソッドでコンポーネントを定義する必要があります:
6363

6464
```ts
6565
import { defineComponent } from 'vue'
6666

6767
const Component = defineComponent({
68-
// type inference enabled
68+
// 型推論が有効になります
6969
})
7070
```
7171

72-
## Using with Options API
72+
## オプション API とともに使用する
7373

74-
TypeScript should be able to infer most of the types without defining types explicitly. For example, if you have a component with a number `count` property, you will have an error if you try to call a string-specific method on it:
74+
TypeScript は明示的に型を定義することなく、ほとんどの型を推論できるようにあるべきです。例えば、数値である `count` プロパティを持つコンポーネントがある場合、文字列に特有のメソッドを呼び出すとエラーになります:
7575

7676
```ts
7777
const Component = defineComponent({
@@ -81,12 +81,12 @@ const Component = defineComponent({
8181
}
8282
},
8383
mounted() {
84-
const result = this.count.split('') // => Property 'split' does not exist on type 'number'
84+
const result = this.count.split('') // => 'split' プロパティは 'number' 型に存在しません
8585
}
8686
})
8787
```
8888

89-
If you have a complex type or interface, you can cast it using [type assertion](https://www.typescriptlang.org/docs/handbook/basic-types.html#type-assertions):
89+
複雑な型や推論の場合、[タイプアサーション (type assertion)](https://www.typescriptlang.org/docs/handbook/basic-types.html#type-assertions) を使用してキャストすることができます:
9090

9191
```ts
9292
interface Book {
@@ -108,9 +108,9 @@ const Component = defineComponent({
108108
})
109109
```
110110

111-
### Annotating Return Types
111+
### 戻り値の型にアノテーションをつける
112112

113-
Because of the circular nature of Vue’s declaration files, TypeScript may have difficulties inferring the types of computed. For this reason, you may need to annotate the return type computed properties.
113+
Vue の型宣言ファイルの循環的な性質により、TypeScript は算出プロパティの型を推論することが困難な場合があります。この理由により、算出プロパティの戻り値の型にアノテーションをつける必要があります。
114114

115115
```ts
116116
import { defineComponent } from 'vue'
@@ -122,12 +122,12 @@ const Component = defineComponent({
122122
}
123123
},
124124
computed: {
125-
// needs an annotation
125+
// アノテーションが必要です
126126
greeting(): string {
127127
return this.message + '!'
128128
}
129129

130-
// in a computed with a setter, getter needs to be annotated
130+
// セッターを持つ算出プロパティのでは、ゲッターにアノテーションが必要です
131131
greetingUppercased: {
132132
get(): string {
133133
return this.greeting.toUpperCase();
@@ -140,9 +140,9 @@ const Component = defineComponent({
140140
})
141141
```
142142

143-
### Annotating Props
143+
### Props にアノテーションをつける
144144

145-
Vue does a runtime validation on props with a `type` defined. To provide these types to TypeScript, we need to cast the constructor with `PropType`:
145+
Vue `type` が定義されたプロパティについてランタイムバリデーションを行います。これらの型を TypeScript に提供するため、`PropType` を伴うコンストラクタをキャストする必要があります:
146146

147147
```ts
148148
import { defineComponent, PropType } from 'vue'
@@ -170,11 +170,12 @@ const Component = defineComponent({
170170
})
171171
```
172172

173-
If you find validator not getting type inference or member completion isn’t working, annotating the argument with the expected type may help address these problems.
173+
バリデータの型推論やメンバの補完が機能していない場合、引数に期待される型のアノテーションをつけることで問題に対処できるかもしれません。
174174

175-
## Using with Composition API
175+
## コンポジション API とともに使用する
176176

177177
On `setup()` function, you don't need to pass a typing to `props` parameter as it will infer types from `props` component option.
178+
`setup()` 関数においては、`props` 引数に型をつける必要はありません。`setup()` 関数は `props` コンポーネントオプションから型を推論するからです。
178179

179180
```ts
180181
import { defineComponent } from 'vue'
@@ -188,15 +189,16 @@ const Component = defineComponent({
188189
},
189190

190191
setup(props) {
191-
const result = props.message.split('') // correct, 'message' is typed as a string
192-
const filtered = props.message.filter(p => p.value) // an error will be thrown: Property 'filter' does not exist on type 'string'
192+
const result = props.message.split('') // 正しいです, 'message' は文字列 (string) として型づけされます
193+
const filtered = props.message.filter(p => p.value) // エラーが起こります: Property 'filter' does not exist on type 'string'
193194
}
194195
})
195196
```
196197

197-
### Typing `ref`s
198+
### `ref` を型定義する
198199

199200
Refs infer the type from the initial value:
201+
Ref は初期値から肩を推論します:
200202

201203
```ts
202204
import { defineComponent, ref } from 'vue'
@@ -210,21 +212,23 @@ const Component = defineComponent({
210212
})
211213
```
212214

213-
Sometimes we may need to specify complex types for a ref's inner value. We can do that simply passing a generic argument when calling ref to override the default inference:
215+
ときどき、ref の内部的な値の複雑な型を特定する必要があるかもしれません。デフォルトの推論をオーバーライドするために ref を呼び出すときに、単純にジェネリック引数を渡すことができます:
214216

215217
```ts
216218
const year = ref<string | number>('2020') // year's type: Ref<string | number>
219+
const year = ref<string | number>('2020') // year の型: Ref<string | number>
217220

218-
year.value = 2020 // ok!
221+
year.value = 2020 // OKです!
219222
```
220223

221-
::: tip Note
224+
::: tip ノート
222225
If the type of the generic is unknown, it's recommended to cast `ref` to `Ref<T>`.
226+
ジェネリックの型が不明の場合、`ref``Ref<T>` にキャストすることを推奨します。
223227
:::
224228

225-
### Typing `reactive`
229+
### `reactive` を型定義する
226230

227-
When typing a `reactive` property, we can use interfaces:
231+
`reactive` プロパティを型定義する場合、推論を使用できます:
228232

229233
```ts
230234
import { defineComponent, reactive } from 'vue'
@@ -238,17 +242,17 @@ export default defineComponent({
238242
name: 'HelloWorld',
239243
setup() {
240244
const book = reactive<Book>({ title: 'Vue 3 Guide' })
241-
// or
245+
// もしくは
242246
const book: Book = reactive({ title: 'Vue 3 Guide' })
243-
// or
247+
// もしくは
244248
const book = reactive({ title: 'Vue 3 Guide' }) as Book
245249
}
246250
})
247251
```
248252

249-
### Typing `computed`
253+
### 算出プロパティを型定義する
250254

251-
Computed values will automatically infer the type from returned value
255+
算出プロパティの値は返り値の型から自動的に推論します:
252256

253257
```ts
254258
import { defineComponent, ref, computed } from 'vue'
@@ -258,10 +262,10 @@ export default defineComponent({
258262
setup() {
259263
let count = ref(0)
260264

261-
// read-only
265+
// 読み取り専用
262266
const doubleCount = computed(() => count.value * 2)
263267

264-
const result = doubleCount.value.split('') // => Property 'split' does not exist on type 'number'
268+
const result = doubleCount.value.split('') // Property 'split' does not exist on type 'number'
265269
}
266270
})
267271
```

0 commit comments

Comments
 (0)