Type Guards and Differnetiating Types
Using type predicates (parameterName is Type)
interface Cat {
numberOfLives: number;
}
interface Dog {
isAGoodBoy: boolean;
}
// Boolean κ°μ returnνλλ° μ’λ μ ννκ² animal is Cat μΌλ‘ ν΄μ€ μ μλ€!
function isCat(animal: Cat | Dog): animal is Cat {
return typeof animal.numberOfLives === 'number';
}Last updated