- Published on
타입스크립트
- Authors

- Name
- dwook
interface는 못하는 Type alias만 가능
- Type alias는 타입에 별칭을 줄 수 있다는 것.
type People = Person[]; // Person[]를 People이라는 타입으로 사용가능.
const people: People = [person, expert];
type Color = 'red' | 'orange' | 'yellow';
const color: Color = 'red';
const colors: Color[] = ['red', 'orange'];
interface와 type 차이점
- interface는 extends 키워드를 이용하지만 type은 & 연산자를 이용
interface PropsInterface {
name: string
age: number
}
interface PropsExtendsInterface extends PropsInterface {
addr: string
}
type PropsType = {
name: string
age: number
}
type PropsExtendsType = PropsType & {
school: string
}
- interface는 동일한 이름으로 다시 실행하면 자동으로 확장
- type은 동일한 이름으로 다시 실행하면 에러
interface PropsInterface {
name: string;
}
interface PropsInterface {
age: number;
}
const props: PropsInterface = {
name: "nung",
age: 11
}
type PropsType {
name: string;
}
type PropsType {
age: number;
}
const props: PropsType = {
name: "nung",
age: 11
}
참조링크