Code Fix

初級implicitly has an 'any' type の原因と直し方 › パターン3

implicitly has an 'any' type の原因と直し方

関数のパラメータに型注釈を付けないと、strictモードのTypeScriptは型を推論できず「暗黙のany」としてエラーにします。

 1  function sum(items: number[], _____________) {
                                        ^
 2    return items.reduce((a, b) => a + b, start);
 3  }
 4  console.log(sum([1, 2, 3], 0));
main.ts(1,31): error TS7006: Parameter 'start' implicitly has an 'any' type.

空欄を埋めてコンパイルを通す

広告
広告スロット(未設定)

implicitly has an 'any' type の原因と直し方

anyは型チェックを無効化してしまうため、TypeScriptの利点を守るために既定で禁止されています。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)