타입 별칭(Alias) 새로운 타입 조합 생성 각각의 타입에 이름을 부여한 후에 원하는 곳에서 재사용할 수 있다 type MyTypeName = string | number; type MyArray = MyTypeName[]; // 별칭 사용 type UserA = { name: string; age: number; }; type UserB = { isValid: boolean; }; type UserX = UserA & UserB; const a: MyTypeName = "A"; // MyTypeName은 string 또는 number 할당 가능 const b: MyArray = [1, "A", "B", 2, 3]; // MyArray는 MyTypeName[]과 같으므로 배열 item으로 string ..
타입 가드(Guard)란? 타입 추론이 가능한 특정 범위(scople) 안에서 타입을 보장한다 instanceof const btn = document.querySelector("button"); if (btn instanceof HTMLButtonElement) { btn.classList.add("btn"); btn.id = "abc"; } const btn = document.querySelector("button"); if (btn) { btn.classList.add("btn"); btn.id = "abc"; } instanceof 를 사용하여 명시적으로 표현해도 되지만 null이 아닌 경우에만 동작하도록 표현해도 괜찮다 typeof function toTwoDecimals(val: number..