본문 바로가기
Language/TypeScript

union(|)과 intersection(&)

by Zayne 2023. 2. 9.

■ type 과 interface

type A = { a: string };
const a: A = { a: "hello" };

// 상속 및 구현이 필요할 경우 interface 사용
interface B {
  a: string;
}
const b: B = { a: "hello" };

 

■ union(|) 

type A = string | number;
const a: A = 5;
const b: A = "hello";

 

■ intersection(&)

type A = { hello: "world" } & { zayne: "lee" };
const a: A = { hello: "world", zayne: "lee" };

 

'Language > TypeScript' 카테고리의 다른 글

void  (0) 2023.02.13
타입과 인터페이스 상속  (0) 2023.02.11
enum, keyof, typeof  (0) 2023.02.07
원시 래퍼 타입, 템플릿 리터럴 타입, rest, 튜플  (0) 2023.02.05
never 타입과 느낌표  (0) 2023.02.04