Created
July 18, 2019 18:04
-
-
Save decapo01/6b1bef816a90e6a772b556eb6634c28d to your computer and use it in GitHub Desktop.
This file contains 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
enum Drink { Beer, Koolaid } | |
enum PersonKind { AdultKind, ChildKind } | |
type Adult = { | |
kind : PersonKind.AdultKind | |
drink : Drink.Beer | |
profession : string | |
} | |
type Child = { | |
kind : PersonKind.ChildKind | |
drink : Drink.Koolaid | |
grade : string | |
} | |
type Person = Adult | Child | |
function describe(p: Person): string { | |
switch(p.kind){ | |
case PersonKind.AdultKind : return p.profession | |
case PersonKind.ChildKind : return p.grade | |
} | |
} | |
const me: Adult = { | |
kind : PersonKind.AdultKind, | |
drink : Drink.Beer, | |
profession: "software developer" | |
} | |
alert(describe(me)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment