Skip to content

Instantly share code, notes, and snippets.

@javcasas
Last active October 9, 2018 15:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javcasas/8f6ae12d1c854c0e36d3ca33509f0435 to your computer and use it in GitHub Desktop.
Save javcasas/8f6ae12d1c854c0e36d3ca33509f0435 to your computer and use it in GitHub Desktop.
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