Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created October 28, 2018 02:05
Show Gist options
  • Save tkssharma/2c0dd675068ced4415ad786130c17dc5 to your computer and use it in GitHub Desktop.
Save tkssharma/2c0dd675068ced4415ad786130c17dc5 to your computer and use it in GitHub Desktop.
interface Book {
type: "book";
isbn: string;
page: number;
}
interface Movie {
type: "movie";
lengthMinutes: number;
}
let hobby: Movie = { type: "movie", lengthMinutes: 120 };
function showHobby(hobby: Book | Movie): void {
if (hobby.type === "movie") {
console.log("Long movie of " + hobby.lengthMinutes);
} else {
console.log("A book of few pages: " + hobby.page);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment