Type vs Interface

김동규·2023년 4월 30일
0

Type의 장점

  1. interface는 유니온 타입을 확장할 수 없다.
type Num = 1 | 2 | 3;

interface Numfour extends num {
	 // X
}

유니온 타입을 확장하려면

type Input = {};
type Output = {};

interface VMap {
	[name: string]: Input | Output; 
}

/* 또는 */
type NVar = (Input | Output) & { name:string };

  1. type 키워드는 복잡한 타입에 유용하다
    • 매핑된 타입
    • 조건부 타입
    • 튜플
    • 배열

Interface의 장점

  1. interface는 보강이 가능하다.
interface Person {
	name: string; 
}

interface Person {
	age: number; 
}
profile
공식문서를 사랑하는 프론트엔드 주니어 개발자

0개의 댓글