스터디 안건: keyof
와 Union(|
), Intersection(&
)을 이용한 아이큐 퀴즈 (?)
interface Person{ name: string; }
interface Lifespan{ birth: Date; death? : Date; }
type K = keyof (Person | Lifespan); //타입이 never
interface Person {
name: string
}
interface Lifespan {
birth: Date
death?: Date
}
type Intersection = keyof (Person & Lifespan) // name, birth, death
type 분배Union = keyof Person | keyof Lifespan // name, birth, death
type Union = keyof (Person | Lifespan) // 타입이 never
type 분배Intersection = keyof Person & keyof Lifespan // never
const k: Intersection = 'name'
const i: Union = 'name'
const m: 분배Intersection = 'name'
const j: 분배Union = 'name'
분배법칙이 NOT처럼 적용된다.