初級 › implicitly has an 'any' type の原因と直し方 › パターン5
implicitly has an 'any' type の原因と直し方
関数のパラメータに型注釈を付けないと、strictモードのTypeScriptは型を推論できず「暗黙のany」としてエラーにします。
1 function shout(___________) { ^ 2 return msg.toUpperCase(); 3 } 4 console.log(shout("hi"));
main.ts(1,16): error TS7006: Parameter 'msg' implicitly has an 'any' type.
空欄を埋めてコンパイルを通す
msgパラメータに型注釈が必要です。msg: stringと明示します。
次の問題