Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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();
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #type #object #typescript
ADD COMMENT
Topic
Name
5+4 =