読み方のヒント

矢印ボタン(または ← → キー)でページを移動できます。

第4節 型のエラーを読んで直す

4.1 エラーの文の組み立て

エラーは、場所・番号・意味の順に書かれています。

src/products.ts:12:5 - error TS2322: Type 'string' is not assignable to type 'number'.

12     price: "220",
       ~~~~~
部分意味
src/products.ts:12:5ファイル、行、列
TS2322エラーの番号。検索するときに使う
Type 'string' is not assignable to type 'number'.何が起きたか
~~~~~エラーの場所

よく出るエラーの文は、型の名前を入れかえた形がほとんどです。

エラーの文意味よくある原因
Type 'A' is not assignable to type 'B'.A を B に入れられない値の型と、変数や引数の型が違う
Property 'x' does not exist on type 'A'.A に x がないつづりのまちがい、しぼりこみ忘れ
'x' is possibly 'undefined'.x が undefined かもしれない確かめずに使っている
Argument of type 'A' is not assignable to parameter of type 'B'.引数の型が違う呼び出し方のまちがい
Expected 2 arguments, but got 1.引数の数が違う引数の渡し忘れ

17 / 20