Skip to content

Instantly share code, notes, and snippets.

@donavon
Created March 6, 2021 11:27
Show Gist options
  • Save donavon/232aaaa1d3889eadcb306690d4936ca3 to your computer and use it in GitHub Desktop.
Save donavon/232aaaa1d3889eadcb306690d4936ca3 to your computer and use it in GitHub Desktop.
TypeScript
const someFunction = (arg: string | string[]) => {
if (Array.isArray(arg)) {
return arg.map<string>(someFunction);
}
return arg.toUpperCase();
};
const x = someFunction('a'); // should be type string
const arr = someFunction(['a']); // should be type string[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment