How to use class with static and non-static member in TypeScript

1 Answer

0 votes
class Circle {
    static pi = 3.14;

    static Area(radius:number) {
        return this.pi * radius * radius;
    }

    Circumference(radius:number):number { 
        return 2 * Circle.pi * radius;
    }
}

console.log(Circle.Area(7)); 

let obj = new Circle();

console.log(obj.Circumference(7));

// obj.Area(7); // Property 'Area' does not exist on type 'Circle'. obj.Area is not a function 




  
      
/*
      
run:
      
153.86 
43.96 
     
*/

 



answered Oct 25, 2021 by avibootz

Related questions

1 answer 182 views
1 answer 198 views
1 answer 197 views
1 answer 271 views
1 answer 128 views
...