[타입스크립트] TypeScript의 Union과 Intersection

minidoo·2020년 10월 29일
0

타입스크립트

목록 보기
4/6
post-thumbnail

Union

union 은 2개 이상의 타입을 '허용'하는 경우이다.
or 의 개념으로 생각하면 된다.

let union : string | number;
union = 2;
union = 'hello';

Intersection

intersection 은 2개 이상의 타입을 '조합'하는 경우이다.
and 의 개념으로 생각하면 된다.

interface Fruit {
  name: string,
  color: string
}

interface Price {
  price: number
}

const apple: Fruit & Price = {
  name: 'apple',
  color: 'red',
  price: 2000
}

0개의 댓글