check type of object typescript

Solutions on MaxInterview for check type of object typescript by the best coders in the world

showing results for - "check type of object typescript"
Manuel
13 Jan 2020
1function isFish(pet: Fish | Bird): pet is Fish {
2   return (<Fish>pet).swim !== undefined;
3}
4
5// Both calls to 'swim' and 'fly' are now okay.
6if (isFish(pet)) {
7  pet.swim();
8}
9else {
10  pet.fly();
11}