내가 보려고 만든 개발 공부 일지

Interface vs Type 본문

Typescript

Interface vs Type

kwangsunny 2021. 7. 2. 00:48

Interface, Type 둘다 타입을 커스텀하게 정의할 필요가 있을때 사용된다.

서로 비슷하지만 각각 소소한 차이점이 있는데 그건 구글링을 하면 상세히 나오니 참고하고,

이것만 기억하자.

--> 가급적 객체 타입 정의는 interface를, 리터럴 타입정의는 type을 사용하라

type myType = "Basic" | "Premium" | "Admin" | null;

interface userInfoProps {
  name: string;
  age: number;
  addr: string;
  onEdit: ()=>void;
}

(참고로 type = 으로 타입정의, interface = 없이 바로 정의)

Comments