-
Notifications
You must be signed in to change notification settings - Fork 0
TypeScript Advanced Type
Yongku cho edited this page May 2, 2019
·
1 revision
참고 사이트 : 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