반응형
SMALL
- never: 공집합
const x: never = 12;
// Type 'number' is not assignable to type 'never'.(2322)
- unknown: 전체집합
- 리터럴타입: 원소가 1개인 집합
- 값이 T에 할당 가능: 값이 T의 원소
- T1이 T2에 할당 가능: T1이 T2의 부분집합
- T1이 T2를 상속: T1이 T2의 부분집합
- T1 | T2: T1과 T2의 합집합
type A = 'A'
type B = 'B';
type Twelve = 12;
type AB = 'A' | 'B';
type AB12 = 'A' | 'B' | 12;
const a: AB = 'A';
const c: AB = 'C'
// Type '"C"' is not assignable to type 'AB'.(2322)
- T1 & T2: T1과 T2의 교집합
interface Person {
name: string;
}
interface Lifespan {
birth: Date;
death?: Date;
}
type PersonSpan = Person & Lifespan;
const ps: PersonSpan = {
name: 'Alan Turing',
birth: new Date('1912/06/23'),
death: new Date('1954/0607')
}
반응형
LIST
'TypeScript' 카테고리의 다른 글
타입단언보다 타입선언을 사용하자(feat. DOM element는 좀 다름) (0) | 2023.02.25 |
---|---|
keyof 사용법 (0) | 2023.02.25 |
| 와 &의 차이 (0) | 2023.02.25 |
코드생성과 타입은 관계가 없음 (0) | 2022.06.19 |
noImplicitAny, strictNullChecks의 선언 (0) | 2022.06.19 |