[TS] 사용자 정의 타입 가드
TIL
사용자 정의 타입 가드란 참 또는 거짓을 반환하는 함수를 이용해 우리 입맛대로 타입 가드를 만들 수 있도록 도와주는 타입스크립트의 문법이다. type Dog = { name: string; isBark: boolean;};type Cat = { name: string; isScratch: boolean;};type Animal = Dog | Cat;Dog와 Cat 두 개의 타입을 정의하고, 두 타입의 유니온 타입인 Animal 타입을 정의했다. function warning(animal: Animal) { if ("isBark" in animal) { console.log(animal.isBark ? "짖습니다" : "안짖어요"); } else if ("isScratch" in anima..