Answers for "check type of object typescript"

0

check type of object typescript

function isFish(pet: Fish | Bird): pet is Fish {
   return (<Fish>pet).swim !== undefined;
}

// Both calls to 'swim' and 'fly' are now okay.
if (isFish(pet)) {
  pet.swim();
}
else {
  pet.fly();
}
Posted by: Guest on September-15-2021

Code answers related to "check type of object typescript"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language