typescript union types apply code example
Example 1: 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;
Example 2: use type as value typescript
Typescript interfaces aren''t being compiled into the js output, and you can not use them at runtime