Notice
Recent Posts
Recent Comments
Link
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- react npm install
- legacy-peer
- npm start
- 이미지반응형
- slickslider
- minwidth
- 의존성문제
- 정적객체
- 아이콘사용법
- 웹아이콘
- node 오류
- XEIcon
- npm install 문제
- maxwidth
- window 정책변경
- node설치
- npm install
- fontawesome
- owlcarousel
- 그누보드반응형
- Git clone
- git lab clone
- 플러그인
- package.json
- 글자들여쓰기
- MediaQuery
- vscode git clone
- 단어단위로떨어지기
- googleicon
- 동적객체
Archives
- Today
- Total
어쩌다 알게 된 ƪ(•̃͡•̃͡ ƪ
🔵 [React/TypeScript] 대수타입 본문
728x90
대수타입
// 대수 타입
// 여러개의 타입을 합성하여 새롭게 만들어낸 타입
// 합집합 타입과 교집합 타입이 존재
// 1. 합집합 - Union 타입
let a: string | number | boolean;
a = 1;
a = "hello";
a = true;
let arr: (number | string | boolean)[] = [1, "hello", true, false];
type Dog = {
name: string;
color: string;
};
type Person = {
name: string;
language: string;
}
type Union1 = Dog | Person;
let union1: Union1 = {
name: "",
color: ""
}
let union2: Union1 = {
name: "",
language: ""
}
let union3: Union1 = {
name: "",
language: "",
color: ""
}
// 2. 교집합 타입 - Intersection 타입
let variable : number & string; // => never
type Intersection = Dog & Person;
// 교집합 타입은 교집합 되는 객체의 모든 속성을 가지지 않으면 에러 발생
// 다 가지고 있어야 함
let intersection : Intersection = {
name: "",
color: "",
language: ""
}
728x90
'개발 > 🔵 React-TypeScript' 카테고리의 다른 글
| 🔵 [React/TypeScript] 타입 좁히기, 서로소 유니온 타입 (0) | 2025.04.05 |
|---|---|
| 🔵 [React/TypeScript] 타입 추론, 타입 단언 (0) | 2025.04.04 |
| 🔵 [React/TypeScript] 타입 호환성 (0) | 2025.04.02 |
| 🔵 [React/TypeScript] 타입 별 예제 2 (0) | 2025.03.30 |
| 🔵 [React/TypeScript] 타입 별 예제 1 (0) | 2025.03.30 |
Comments
