Last active
February 22, 2018 22:03
-
-
Save rarmatei/8580abb9822dd9710387b2a9fb8a0833 to your computer and use it in GitHub Desktop.
typescript type guards
This file contains hidden or 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
class Book { | |
title: string; | |
} | |
class Television { | |
screenSize: string; | |
} | |
function relaxWith(item: Book | Television) { | |
if(item instanceof Book) { | |
console.log(item.title); | |
} else { | |
console.log(item.screenSize); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment