Item 1-7 Study Summary
์คํฐ๋ ์๊ฑด: keyof
์ Union(|
), Intersection(&
)์ ์ด์ฉํ ์์ดํ ํด์ฆ (?)
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
PreviousItem 7 ํ์
์ด ๊ฐ๋ค์ ์งํฉ์ด๋ผ๊ณ ์๊ฐํ๊ธฐNextItem 8 ํ์
๊ณต๊ฐ๊ณผ ๊ฐ ๊ณต๊ฐ์ ์ฌ๋ฒ ๊ตฌ๋ถํ๊ธฐ
Last updated
Was this helpful?