Skip to content

Instantly share code, notes, and snippets.

@maddymanu
Created May 2, 2020 19:25
Show Gist options
  • Select an option

  • Save maddymanu/500262ac61f41ac97ded3e5cd9d71785 to your computer and use it in GitHub Desktop.

Select an option

Save maddymanu/500262ac61f41ac97ded3e5cd9d71785 to your computer and use it in GitHub Desktop.
Simple Unions Example
// Introduction
type Human = {
name: string,
age: number
}
type Alien = {
name: string,
planet: string
}
type Named = Human | Alien;
function sayHello(inp: Named) {
console.log(`Hi ${inp.name}`);
}
const adi: Human = {name: 'Adi', age: 18};
sayHello(adi); // 'Hi Adi'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment