TSConfig

noImplicitThis

Raise error on ‘this’ expressions with an implied ‘any’ type.

For example, the class below returns a function which tries to access this.width and this.height – but the context for this inside the function inside getAreaFunction is not the instance of the Rectangle.

ts
class Rectangle {
width: number;
height: number;
 
constructor(width: number, height: number) {
this.width = width;
this.height = height;
}
 
getAreaFunction() {
return function () {
return this.width * this.height;
'this' implicitly has type 'any' because it does not have a type annotation.
'this' implicitly has type 'any' because it does not have a type annotation.
2683
2683
'this' implicitly has type 'any' because it does not have a type annotation.
'this' implicitly has type 'any' because it does not have a type annotation.
};
}
}
Try