Typescript 객체 타입 정의 type vs interface


Typescript 객체 타입 정의 type vs interface

Typescript에서 객체 타입을 만드는 방법 중에 type과 interface가 있습니다. 사용방법이나 사용 이유가 거의 비슷한데요. 많은 프로젝트에서 2가지 방법중에 고민하는 경우가 많이 있습니다. 간략하게 비교해보면 아래와 같습니다. type과 interface의 유사한 기능 1. 선언 type BirdType = { wings: 2; }; interface BirdInterface { wings: 2; } const bird1: BirdType = { wings: 2 }; const bird2: BirdInterface = { wings: 2 }; 2. 확장 - type은 & 사용 - interface는 extends를 사용하여 확장 type Robin = { nocturnal: false } & BirdInterface; interface Peacock extends BirdType { colourful: true; flies: false; } type과 interface...


#interface #type #Typescript

원문링크 : Typescript 객체 타입 정의 type vs interface