# 一般的なエラー

このセクションでは、ユーザーが現実世界で経験する多くの一般的なエラーコードについて説明します。

## TS2304

サンプル：

> `Cannot find name ga` `Cannot find name $` `Cannot find module jquery`

おそらく第三者のライブラリ(Googleアナリティクスなど)を使用しており、宣言していません。TypeScriptは、\_スペルミス\_や宣言しないで変数を使用すると、あなたを助けようとします。あなたは外部ライブラリを取り込んでいるので実行時に利用可能なものに明示する必要があります([修正方法](/deep-dive/type-system/intro/d.ts.md))。

## TS2307

サンプル：

> `Cannot find module 'underscore'`

おそらく、サードパーティのライブラリ(underscoreなど)を\_モジュール\_([モジュールの詳細はこちらです](/deep-dive/project/modules.md))として使用していて、それに対する環境宣言ファイルがありません。

## TS1148

サンプル：

> `Cannot compile modules unless the '--module' flag is provided`

[モジュール](/deep-dive/project/modules.md)のセクションをチェックしてください。

## キャッチ句の変数は型アノテーションを持つことはできません(Catch clause variable cannot have a type annotation)

サンプル：

```javascript
try { something(); }
catch (e: Error) { // Catch clause variable cannot have a type annotation
}
```

TypeScriptはワイルドで間違ったJavaScriptからあなたを守ろうとします。Type Guardを代わりに使ってください。

```javascript
try { something(); }
catch (e) {
  if (e instanceof Error){
    // Here you go.
  }
}
```

## Interface `ElementClass`は`Component`と `Component`の型を同時に継承することはできません。(Interface `ElementClass` cannot simultaneously extend types `Component` and `Component`)

これはコンパイルコンテキストに2つの`react.d.ts`(`@types/react/index.d.ts`)があるときに起こります。

**修正**：

* `node_modules`と`package-lock`(またはyarn lock)を削除したあと、`npm install`をもう一度実行してください。
* うまくいかない場合は、無効なモジュールを見つけてください(あなたのプロジェクトで使われているすべてのモジュールは`react.d.ts`を`peerDependency`とするべきです。hardな`dependency`は持たないようにしてください)。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://typescript-jp.gitbook.io/deep-dive/main/common-errors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
