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