Normally you would use the keyword class to create a class in JS as
class Car {
constructor(make, model) {
this.make = make;
this.model = model;
}
}
var car = new Car('Nissan', 'Sunny');
But I'm using ES5 to declare classes as
function Car(make, model) {
this.make = make;
this.model = model;
}
var car = new Car('Nissan', 'Sunny');
My problem is that I get a Typescript error for this
'this' implicitly has type 'any' because it does not have a type annotation.
so I add
function Car<T>(this:T, make:any, model:any) {
this.make = make;
this.model = model;
}
but it gives me another error for this.make
Property 'make' does not exist on type 'T'.
When I add any to this
function Car(this:any, make:any, model:any) {
this.make = make;
this.model = model;
}
It goes away, but I'm not sure if using any is the right choice. I need some advice in this.