Created
September 26, 2014 18:57
-
-
Save lukehoban/7d652f5a6cfb696b5ed9 to your computer and use it in GitHub Desktop.
Union types
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
function $(x: string | Element): { elem: Element } { | |
if(x instanceof Element) { | |
return { elem: document.getElementById(x) } // do I have to say <string>x here? | |
} else { | |
return { elem: x } // do I have to say <Element>x here? | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment