Skip to content

Instantly share code, notes, and snippets.

@colinbes
Created November 17, 2021 21:49
Show Gist options
  • Select an option

  • Save colinbes/06428abc49267772e912b6a4694235f9 to your computer and use it in GitHub Desktop.

Select an option

Save colinbes/06428abc49267772e912b6a4694235f9 to your computer and use it in GitHub Desktop.
Discriminated Unions
interface MyError {
type: "error";
item: {status: number, msg: string};
}
interface MyNums {
type: "mynums";
item: number[];
}
interface MyNum {
type: "mynum";
item: number;
}
type Generic = MyError | MyNum | MyNums
let test: Generic = {
type: "error",
item: {status: 10, msg: 'hello'}
}
let test1: Generic = {
type: "mynum",
item: 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment