TypeScriptバージョン: 2.2.1 /毎晩(2.2.0-dev.201xxxxx)
2.3.3
コード
strictはtrueです
function test(){
console.log(this.value);
console.log((this as any).value);
}
let a = {
value: 'a',
test: test
}
a.test()
予想される行動:
サク
実際の動作:
Test.ts(2,17):エラーTS2683: 'this'には型注釈がないため、暗黙的に型 'any'があります。
Test.ts(3,18):エラーTS2683: 'this'には型注釈がないため、暗黙的に型 'any'があります。
関数の宣言でthis
タイプを指定します。
function test(this: any) {
console.log(this.value);
}
または--noImplicitThis false
切り替え
最も参考になるコメント
関数の宣言で
this
タイプを指定します。または
--noImplicitThis false
切り替え