대수 타입

김정현·2023년 8월 7일
0

TypeScript

목록 보기
12/12

1. Union Type ( 합 집합 )

기본 타입 Union

let a: string | number;
a = 1;
a = "Hello

객체 Union Type

type Dog = {
	name: string;
	color: string;
}

type Person = {
	name: string;
	language: string;
}

type Union1 = Dog | Person

2. Intersection Type ( 교 집합 )

기본 타입의 Intersection Type은 never의 경우가 많다.

let variable: number & string;

객체 타입의 Intersection Type은 조합하는 객체 타입의 모든 값을 가지고 있어야 한다.

type Intersection = Dog & Person

let intersection1: Intersection = {
	name: "",
	color: "",
	language: ""
}
profile
개발일지

0개의 댓글