Last active
October 9, 2018 15:31
-
-
Save javcasas/8f6ae12d1c854c0e36d3ca33509f0435 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
type MyADT = { | |
t: "Case1"; | |
v1: string; | |
} | { | |
t: "Case2"; | |
v2: string; | |
at: number; | |
} | { | |
t: "Case3", | |
v2: string | |
}; | |
const x: MyADT = { t: "Case2", v2: "asdf", at: 4 }; | |
function process(v: MyADT) { | |
switch (x.t) { | |
case "Case1": | |
return console.log(x.v1); | |
case "Case2": | |
return console.log(x.v2); | |
case "Case3": | |
return console.log(x.v2); | |
} | |
} | |
process(x); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment