📎아이템 13 타입과 인터페이스의 차이점 알기
📍 타입스크립트에서 명명된 타입(named type)을 정의하는 방법은 두가지이다.
⭐️ 타입을 사용하는 방법
type TState = {
name: string;
capital: string;
};⭐️ 인터페이스를 사용하는 방법
interface IState {
name: string;
capital: string;
}인터페이스 선언과 타입 선언의 비슷한 점
const wyoming: TState = {
name: 'Wyoming',
capital: 'Cheyenne',
population: 578_000
// ~~~~~~~ Object literal may only specify known properties,
// and 'population' does not exist in type 'TState'
// ... 형식은 'Tstate' 형식에 할당할 수 없다.
// 개체 리터럴은 알려진 속성만 지정할 수 있으며, 'TState' 형식에 'populatio'이 없다.
};인터페이스 선언과 타입 선언의 다른 점
📍타입 VS 인터페이스
📍요약
Last updated