Skip to content

Instantly share code, notes, and snippets.

@lukehoban
Created September 26, 2014 18:57
Show Gist options
  • Save lukehoban/7d652f5a6cfb696b5ed9 to your computer and use it in GitHub Desktop.
Save lukehoban/7d652f5a6cfb696b5ed9 to your computer and use it in GitHub Desktop.
Union types
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