'Iterate over the types in a dicsriminated union type

In TypeScript can you iterate over all the component types of a discriminated union type? For example if I declare

interface Cat {}
interface Dog {}

type Animal = Cat | Dog

and would like to iterate over all animals in code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source