TypeScript의 연산자 활용 타입
1. 유니온(Union) 타입
function printValue(value: any): void { if (typeof value === "number") { console.log(`The value is a number: ${value}`); } else { console.log(`The value is a string: ${value}`); } } printValue(10); // The value is a number: 10 printValue("hello"); // The value is a string: hellofunction printValue(value: number|string): void { if (typeof value === "number") { console.log(`The value is a number: ${value}`); } else { console.log(`The value is a string: ${value}`); } } printValue(10); // The value is a number: 10 printValue("hello"); // The value is a string: hello
(1) 유니온(Union) 타입의 장점
(2) 유니온(Union) 타입 사용 시 유의할 점
2. 인터섹션(Intersection) 타입
Last updated