Defining a Union Type 타입을 2개 이상 조합하여 사용하는것이 조합형 유니온 타입이다. 하나의 유니온 타입을 구성하는 요소 타입을 유니온 멤버라고 한다. function handler(name: number | string) { .... } handler("john"); // OK handler(123); // OK handler(false); // NO 유니온을 사용하고 타입을 추론할때 "typeof"를 활용하면 된다. function handler(name: number | string) { if (typeof name === "string") { // 유니온 타입은 2개 이지만 타입을 추론하여 "string" 일 때 처리할 수 있다. } else { // "string" 타입이 아닌 "number" 일때 } }...
#type
#타입스크립트
#타입
#추론
#유니온타입
#유니온멤버
#유니온
#uniontype
#union
#typescript
#typeof
#타입추론
원문링크 : [TypeScript] 타입스크립트 유니온 타입(Defining a Union Type)