typescript how to work with union types code example
Example 1: union value typescript
let myVar : string | number; //myVar can store string and number types
Example 2: typescript union types
type Cow = {
name: string;
moo: () => void;
};
type Dog = {
name: string;
bark: () => void;
};
type Cat = {
name: string;
meow: () => void;
};
// union type
type Animals = Cow | Dog | Cat;