TypeScript Advanced Type - ChoDragon9/posts GitHub Wiki

μ°Έκ³  μ‚¬μ΄νŠΈ : https://infoscis.github.io/2017/06/19/TypeScript-handbook-advanced-types/

  • Union Type : μ—¬λŸ¬ νƒ€μž…μ„ 지정할 λ•Œ μ‚¬μš©ν•œλ‹€.
const merge = (a: string | number, b: string | number): string => `${a}${b}`
  • instanceof : νƒ€μž… 처리 λ²”μœ„λ₯Ό 쒁힐 λ•Œ μ‚¬μš©ν•œλ‹€.
type Name = string
type Age = number

if (str instanceof Name) {
 // Name만 확인
}
if (str instanceof Age) {
 // Age만 확인
}
  • Alias : νƒ€μž…μ„ μ°Έμ‘°ν•˜λŠ” μƒˆμ΄λ¦„μ„ μž‘μ„±ν•œλ‹€. μ»€μŠ€ν…€ 타일을 톡해 μƒˆλ‘œμš΄ μ»€μŠ€ν…€ νƒ€μž…μ΄ ν•„μš”ν•  λ•Œ μ‚¬μš©
type Name = string
type Age = number
type Info = Name | Age // Alias