TypeScriptエラー
12件の記事
概要
TypeScriptのコンパイルエラーとランタイムエラーの診断ガイドです。型の不一致、null安全、モジュール解決などの問題を解決します。
どこでエラーが出た?
| 状況 | エラー | 主な原因 |
|---|---|---|
| 型の不一致(コンパイル時) | TS2322: Type ‘X’ is not assignable to type ‘Y’ | 型の互換性なし |
| TS2345: Argument type not assignable | 引数の型が不一致 | |
| プロパティエラー | TS2339: Property does not exist on type | 存在しないプロパティアクセス |
| Cannot assign to read-only property | readonly への代入 | |
| null / undefined | Object is possibly ‘undefined’ | strictNullChecks での未チェック |
| TS7006: Parameter implicitly has ‘any’ type | noImplicitAny での型注釈不足 | |
| モジュール | Cannot find module | 型定義・パス設定の問題 |
| ECMAScript imports/exports only | esModuleInterop 設定 | |
| Cannot augment module | モジュール拡張の構文エラー | |
| デコレータ | Decorators are not valid here | experimentalDecorators 設定 |
| ランタイムエラー | Cannot read properties of null | null参照 |
| X is not iterable | 非イテラブルへの反復処理 |
切り分けフローチャート
TypeScriptエラー発生
├── TSxxxx コンパイルエラー?
│ ├── TS2322 / TS2345: 型の不一致 → type-not-assignable / argument-type-not-assignable
│ ├── TS2339: プロパティが存在しない → property-does-not-exist
│ ├── TS2540: readonly → readonly-property
│ ├── TS7006: implicit any → implicit-any
│ └── TS18048: possibly undefined → object-is-possibly-undefined
├── モジュール関連?
│ ├── "Cannot find module" → cannot-find-module
│ ├── "ECMAScript imports" → esmodule-interop
│ └── "Cannot augment" → module-augmentation
├── デコレータ?
│ └── "not valid here" → decorator-not-valid
└── ランタイムエラー?
├── "Cannot read properties of null" → cannot-read-properties-of-null
└── "is not iterable" → not-iterable
型の不一致(コンパイル時)?
プロパティエラー?
null / undefined / any?
モジュール?
ランタイム / デコレータ?
お探しの環境がありませんか?
全記事一覧
- Cannot assign to 'x' because it is a read-only property
- Cannot find module or its corresponding type declarations
- Object is possibly 'undefined'
- This module can only be referenced with ECMAScript imports/exports
- TS2339: Property 'x' does not exist on type 'Y'
- TS2345: Argument of type 'X' is not assignable to parameter of type 'Y'
- TS7006: Parameter 'x' implicitly has an 'any' type
- Type 'X' is not assignable to type 'Y'
- TypeError: Cannot read properties of null
- TypeError: X is not iterable
- TypeScript: Cannot augment module
- TypeScript: Decorators are not valid here
この記事は役に立ちましたか?