TypeScript문법2

Jay·2021년 2월 20일
0

interface

  • 클래스 or 객체를 위한 타입 지정 문법
interface Shape {
 getArea():number; 
}

class Circle implements Shape {
  radius: number;
  constructor(radius:number){
   this.radius = radius 
  }
  getArea(){
  return this.radius * this.radius * Math.PI; 
 }
}

class Rectangle implements Shape {
 width: number;
 height: number;
 constructor(width:number,height:number){
 this.width = width;
 this.height = height;
 }
 getArea(){
  return this.width * this.height 
 }
}

const circle = new Circle(5);
const rectangle = new Rectangle(2,5)
profile
programming!

0개의 댓글