Item 1-7 Study Summary

์Šคํ„ฐ๋”” ์•ˆ๊ฑด: 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์ฒ˜๋Ÿผ ์ ์šฉ๋œ๋‹ค.

  • keyof (A & B) == keyof A | keyf B == A์™€ B์˜ ํ‚ค์˜ ํ•ฉ์ง‘ํ•ฉ

  • keyof (A | B) == keyof A & keyof B == never

Last updated