In my typescript, there is a method added in static. later I am trying to call the same. But getting error... while compile the code. anything wrong with my code? any one help me to understand the static properties in typescript?
Here is my code :
class Car {
private distanceRun: number = 0;
color: string;
constructor(public hybrid:boolean, color:string="red") {
this.color = color;
}
getGasConsumption():string {
return this.hybrid ? "Low" : "High";
}
drive(distance:number) {
return this.distanceRun += distance;
}
static horn():string {
return "HOOONK!";
}
get distance():number {
return this.distanceRun;
}
}
let newCar = new Car(false);
console.log(newCar.color);
console.log(newCar.horn()); //shows error as Property 'horn' does not exist on type 'Car'..