Skip to content

Commit 08c3880

Browse files
authored
translate 05-misc/03-typescript.md into Japanese (#598)
1 parent e906d73 commit 08c3880

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

documentation/docs/05-misc/03-typescript.md

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
title: TypeScript
33
---
44

5-
You can use TypeScript within Svelte components. IDE extensions like the [Svelte VSCode extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) will help you catch errors right in your editor, and [`svelte-check`](https://www.npmjs.com/package/svelte-check) does the same on the command line, which you can integrate into your CI.
5+
Svelte コンポーネント内では TypeScript が使用できます。[Svelte VSCode extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) などの IDE の拡張機能を使用すると、エディター上でエラーをすぐに見つけやすくなります。また、[`svelte-check`](https://www.npmjs.com/package/svelte-check) は同じことをコマンドライン上で実行できるため、CI と統合できます。
66

7-
## Setup
7+
## セットアップ
88

9-
To use TypeScript within Svelte components, you need to add a preprocessor that will turn TypeScript into JavaScript.
9+
Svelte コンポーネント内で TypeScript を使用するには、TypeScript JavaScript に変換するプリプロセッサーを追加する必要があります。
1010

11-
### Using SvelteKit or Vite
11+
### SvelteKit または Vite を使用する
1212

13-
The easiest way to get started is scaffolding a new SvelteKit project by typing `npm create svelte@latest`, following the prompts and choosing the TypeScript option.
13+
TypeScript を使い始めるのに最も簡単な方法は、`npm create svelte@latest` とタイプして、新しい SvelteKit プロジェクトを scaffold し、プロンプトに従って TypeScript オプションを選択することです。
1414

1515
```ts
1616
/// file: svelte.config.js
@@ -24,7 +24,7 @@ const config = {
2424
export default config;
2525
```
2626

27-
If you don't need or want all the features SvelteKit has to offer, you can scaffold a Svelte-flavoured Vite project instead by typing `npm create vite@latest` and selecting the `svelte-ts` option.
27+
SvelteKit が提供するすべての機能が必要ではない場合は、`npm create vite@latest` とタイプして `svelte-ts` オプションを選ぶことで、Svelte 向けの Vite プロジェクトを scaffold できます。
2828

2929
```ts
3030
/// file: svelte.config.js
@@ -37,17 +37,17 @@ const config = {
3737
export default config;
3838
```
3939

40-
In both cases, a `svelte.config.js` with `vitePreprocess` will be added. Vite/SvelteKit will read from this config file.
40+
いずれの場合でも、`vitePreprocess` を使用した `svelte.config.js` が追加されます。Vite/SvelteKit はこの設定ファイルを読み込みます。
4141

42-
### Other build tools
42+
### その他のビルドツール
4343

44-
If you're using tools like Rollup or Webpack instead, install their respective Svelte plugins. For Rollup that's [rollup-plugin-svelte](https://github.com/sveltejs/rollup-plugin-svelte) and for Webpack that's [svelte-loader](https://github.com/sveltejs/svelte-loader). For both, you need to install `typescript` and `svelte-preprocess` and add the preprocessor to the plugin config (see the respective READMEs for more info). If you're starting a new project, you can also use the [rollup](https://github.com/sveltejs/template) or [webpack](https://github.com/sveltejs/template-webpack) template to scaffold the setup from a script.
44+
代わりに Rollup Webpack のようなツールを使用している場合、ツール向けの Svelte プラグインをインストールしてください。Rollup の場合は [rollup-plugin-svelte](https://github.com/sveltejs/rollup-plugin-svelte)Webpack の場合は[svelte-loader](https://github.com/sveltejs/svelte-loader) です。どちらの場合も、`typescript` `svelte-preprocess` をインストールして、プリプロセッサーをプラグインの設定に追加する必要があります(より詳しい情報については、それぞれのREADMEを確認してください)。新しいプロジェクトを開始する場合には、[rollup](https://github.com/sveltejs/template) [webpack](https://github.com/sveltejs/template-webpack) のテンプレートを使ってスクリプトからセットアップを scaffold することもできます。
4545

46-
> If you're starting a new project, we recommend using SvelteKit or Vite instead
46+
> 新しいプロジェクトを開始する場合は、代わりに SvelteKit または Vite を使うことをおすすめします。
4747
4848
## `<script lang="ts">`
4949

50-
To use TypeScript inside your Svelte components, add `lang="ts"` to your `script` tags:
50+
Svelte コンポーネント内で TypeScript を使うには、`lang="ts"` `script` タグに追加します。
5151

5252
```svelte
5353
<script lang="ts">
@@ -61,7 +61,7 @@ To use TypeScript inside your Svelte components, add `lang="ts"` to your `script
6161

6262
### Props
6363

64-
Props can be typed directly on the `export let` statement:
64+
Props は、`export let` 文に直接型付けできます。
6565

6666
```svelte
6767
<script lang="ts">
@@ -71,7 +71,7 @@ Props can be typed directly on the `export let` statement:
7171

7272
### Slots
7373

74-
Slot and slot prop types are inferred from the types of the slot props passed to them:
74+
Slot slot prop の型は、渡された slot props の型から推論されます。
7575

7676
```svelte
7777
<script lang="ts">
@@ -82,23 +82,23 @@ Slot and slot prop types are inferred from the types of the slot props passed to
8282
8383
<!-- Later -->
8484
<Comp let:name>
85-
<!-- ^ Inferred as string -->
85+
<!-- ^ string として推論される -->
8686
{name}
8787
</Comp>
8888
```
8989

9090
### Events
9191

92-
Events can be typed with `createEventDispatcher`:
92+
Event は `createEventDispatcher` を使って型付けできます。
9393

9494
```svelte
9595
<script lang="ts">
9696
import { createEventDispatcher } from 'svelte';
9797
9898
const dispatch = createEventDispatcher<{
99-
event: null; // does not accept a payload
100-
click: string; // has a required string payload
101-
type: string | null; // has an optional string payload
99+
event: null; // payload を受け付けない
100+
click: string; // 必須の string payload を持つ
101+
type: string | null; // オプションの string payload を持つ
102102
}>();
103103
104104
function handleClick() {
@@ -115,32 +115,32 @@ Events can be typed with `createEventDispatcher`:
115115
<button on:click={handleClick} on:keydown={handleType}>Click</button>
116116
```
117117

118-
## Enhancing built-in DOM types
118+
## ビルトインのDOM型を拡張する
119119

120-
Svelte provides a best effort of all the HTML DOM types that exist. Sometimes you may want to use experimental attributes or custom events coming from an action. In these cases, TypeScript will throw a type error, saying that it does not know these types. If it's a non-experimental standard attribute/event, this may very well be a missing typing from our [HTML typings](https://github.com/sveltejs/svelte/blob/master/packages/svelte/elements.d.ts). In that case, you are welcome to open an issue and/or a PR fixing it.
120+
Svelte はベストエフォートで存在する全ての HTML DOM の型を提供します。ときには実験的な属性やアクションから来るカスタムイベントを使いたい場合があるかもしれません。そのような場合には、TypeScript が型エラーを発生し、未知の型であると報告します。もし実験的ではない標準の属性やイベントであるなら、Svelte の [HTML ](https://github.com/sveltejs/svelte/blob/master/packages/svelte/elements.d.ts) から来た型付けの誤りによる可能性があります。その場合、issue や修正の PR を歓迎します。
121121

122-
In case this is a custom or experimental attribute/event, you can enhance the typings like this:
122+
これがカスタムまたは実験的な属性またはイベントの場合、以下のように型を拡張できます。
123123

124124
```ts
125125
/// file: additional-svelte-typings.d.ts
126126
declare namespace svelteHTML {
127-
// enhance elements
127+
// 要素の拡張
128128
interface IntrinsicElements {
129129
'my-custom-element': { someattribute: string; 'on:event': (e: CustomEvent<any>) => void };
130130
}
131-
// enhance attributes
131+
// 属性の拡張
132132
interface HTMLAttributes<T> {
133-
// If you want to use on:beforeinstallprompt
133+
// on:beforeinstallprompt を使用したい場合
134134
'on:beforeinstallprompt'?: (event: any) => any;
135-
// If you want to use myCustomAttribute={..} (note: all lowercase)
136-
mycustomattribute?: any; // You can replace any with something more specific if you like
135+
// myCustomAttribute={..} (注意: すべて小文字) を使用したい場合
136+
mycustomattribute?: any; // 望むなら any をより特定の型に置き換えられます
137137
}
138138
}
139139
```
140140

141-
Then make sure that `d.ts` file is referenced in your `tsconfig.json`. If it reads something like `"include": ["src/**/*"]` and your `d.ts` file is inside `src`, it should work. You may need to reload for the changes to take effect.
141+
そして、`d.ts` ファイルが `tsconfig.json` で参照されるようにします。`"include": ["src/**/*"]` のような設定があり、`d.ts` ファイルが `src` 内にあれば、上手く動作するはずです。変更を反映するためには再読み込みが必要なことがあります。
142142

143-
Since Svelte version 4.2 / `svelte-check` version 3.5 / VS Code extension version 107.10.0 you can also declare the typings by augmenting the `svelte/elements` module like this:
143+
Svelte バージョン 4.2 / `svelte-check` バージョン 3.5 / VS Code 拡張機能 107.10.0 以降では、以下のように `svelte/elements` モジュールを拡張することでも型を宣言できるようになりました。
144144

145145
```ts
146146
/// file: additional-svelte-typings.d.ts
@@ -151,52 +151,52 @@ declare module 'svelte/elements' {
151151
'custom-button': HTMLButtonAttributes;
152152
}
153153

154-
// allows for more granular control over what element to add the typings to
154+
// 型を追加する要素へのより細かい制御を可能にする
155155
export interface HTMLButtonAttributes {
156156
veryexperimentalattribute?: string;
157157
}
158158
}
159159

160-
export {}; // ensure this is not an ambient module, else types will be overridden instead of augmented
160+
export {}; // これが ambient module ではなく、他の型が拡張される代わりに上書きされることを保証する
161161
```
162162

163-
## Experimental advanced typings
163+
## 実験的な高度な型付け
164164

165-
A few features are missing from taking full advantage of TypeScript in more advanced use cases like typing that a component implements a certain interface, explicitly typing slots, or using generics. These things are possible using experimental advanced type capabilities. See [this RFC](https://github.com/dummdidumm/rfcs/blob/ts-typedefs-within-svelte-components/text/ts-typing-props-slots-events.md) for more information on how to make use of them.
165+
特定のインターフェイスを実装するコンポーネントの型付け、明示的に型付けされた slot、ジェネリクスの使用など、より高度なユースケースで TypeScript を最大限に活用するには、いくつかの機能が欠けています。これらの機能は、実験的な高度な型機能を利用することで実現可能です。使用方法に関するより詳しい情報は、[この RFC](https://github.com/dummdidumm/rfcs/blob/ts-typedefs-within-svelte-components/text/ts-typing-props-slots-events.md) を参照してください。
166166

167-
> The API is experimental and may change at any point
167+
> API は実験的であるため、いつでも変更される可能性があります
168168
169-
## Limitations
169+
## 制限事項
170170

171-
### No TS in markup
171+
### マークアップ内ではTSは使えない
172172

173-
You cannot use TypeScript in your template's markup. For example, the following does not work:
173+
TypeScript はテンプレートのマークアップ内では使えません。たとえば、次のコードは機能しません。
174174

175175
```svelte
176176
<script lang="ts">
177177
let count = 10;
178178
</script>
179179
180-
<h1>Count as string: {count as string}!</h1> <!-- ❌ Does not work -->
180+
<h1>Count as string: {count as string}!</h1> <!-- ❌ 動かない -->
181181
{#if count > 4}
182-
{@const countString: string = count} <!-- ❌ Does not work -->
182+
{@const countString: string = count} <!-- ❌ 動かない -->
183183
{countString}
184184
{/if}
185185
```
186186

187-
### Reactive Declarations
187+
### リアクティブな宣言
188188

189-
You cannot type your reactive declarations with TypeScript in the way you type a variable. For example, the following does not work:
189+
TypeScript を使用したリアクティブな宣言に対しては、変数と同じように型付けすることはできません。たとえば、次のコードは動作しません。
190190

191191
```svelte
192192
<script lang="ts">
193193
let count = 0;
194194
195-
$: doubled: number = count * 2; // ❌ Does not work
195+
$: doubled: number = count * 2; // ❌ 動かない
196196
</script>
197197
```
198198

199-
You cannot add a `: TYPE` because it's invalid syntax in this position. Instead, you can move the definition to a `let` statement just above:
199+
この位置では無効な構文となるため、`: TYPE` を追加することはできません。その代わり、型の定義を直前の `let` 文に移動できます。
200200

201201
```svelte
202202
<script lang="ts">

0 commit comments

Comments
 (0)