implement

김범주·2022년 7월 18일
0

typescript

목록 보기
20/23
post-thumbnail
interface CarType {
  model : string,
  price : number
}

class Car implements CarType {
  model : string;
  price : number = 1000;
  constructor(a :string){
    this.model = a
  }
}
let 붕붕이 = new Car('morning');

class 이름 우측에 implements를 쓰고 interface 이름을 쓰면
"이 class가 이 interface에 있는 속성을 다 들고있는가"
라는 확인이 가능

빠진 속성이 있으면 에러
class에다가 타입을 할당하고 변형시키는 키워드는 아님, 확인만 하는 것

profile
개발꿈나무

0개의 댓글