Created
May 2, 2020 19:25
-
-
Save maddymanu/500262ac61f41ac97ded3e5cd9d71785 to your computer and use it in GitHub Desktop.
Simple Unions Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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