TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)
2.3.3
Code
strict is true
function test(){
console.log(this.value);
console.log((this as any).value);
}
let a = {
value: 'a',
test: test
}
a.test()
Expected behavior:
succ
Actual behavior:
Test.ts(2,17): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
Test.ts(3,18): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
Either specify a this
type in your function declatation:
function test(this: any) {
console.log(this.value);
}
or switch of --noImplicitThis false
Most helpful comment
Either specify a
this
type in your function declatation:or switch of
--noImplicitThis false