Skip to content

Instantly share code, notes, and snippets.

@donnut
Created February 9, 2015 10:37
Show Gist options
  • Save donnut/64ad9017ea7b78da379d to your computer and use it in GitHub Desktop.
Save donnut/64ad9017ea7b78da379d to your computer and use it in GitHub Desktop.
unions and type guard
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