Typescript: understanding type guards

Example:

function isFish(pet: Fish | Bird): pet is Fish {
  return (pet as Fish).swim !== undefined;
}
Type guards help in narrowing down the type within a certain scope using custom logic.

Solution:

// Use type guards to differentiate between types based on custom logic.

Beginner's Guide to TypeScript