Created
February 9, 2015 10:37
-
-
Save donnut/64ad9017ea7b78da379d to your computer and use it in GitHub Desktop.
unions and type guard
This file contains 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
interface IMessage { | |
name: string; | |
} | |
function itemFn(pipIn: string[]) { | |
return pipIn; | |
} | |
function baseFn(pipIn: string) { | |
return [pipIn]; | |
} | |
function main(pipIn: string|string[]) { | |
if (pipIn instanceof Array) { | |
return itemFn(pipIn); | |
} else { | |
return baseFn(pipIn); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment