개발/TypeScript
[TypeScript] interface vs type alias에 대한 개인적인 생각
타입스크립트에서 타입을 별도로 선언하는 방법으로는 interface와 type alias가 있는데 이 둘에 대해서 간단하게 알아보려고 합니다. 타입을 표현할 때 interface는 reference type의 타입을 표현한다. type alias는 primitive type, reference type 타입을 모두 표현할 수 있다. 타입을 중복 정의할 때 interface는 선언 병합(declaration merging)이 된다. type alias는 에러가 발생한다. 타입을 확장할 때 interface는 extends 키워드를 사용한다. type alias는 &(intersection) 연산자를 사용한다. 내부 동작을 제외하고 사용하는 관점에서는 이런 차이들이 있는 것 같습니다. 그래서 뭘 쓰면 좋을..