TypeScript版本: 2.2.1 /每晚(2.2.0-dev.201xxxxx)
2.3.3
码
严格是真的
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