Skip to content

Instantly share code, notes, and snippets.

@rchaser53
Created February 25, 2017 13:23
Show Gist options
  • Save rchaser53/2f52dc8ef540e4521184fda0cfd4cc86 to your computer and use it in GitHub Desktop.
Save rchaser53/2f52dc8ef540e4521184fda0cfd4cc86 to your computer and use it in GitHub Desktop.
continueとreturnでのunion typeの挙動
// for文内のcontinueはNG
const abc = (arg: (string | number)[]) => {
for (let i=0;i<arg.length;i++) {
if (typeof arg[i] === 'string') continue;
const abc: number = arg[i];
}
}
// if文のearly returnはOK
const abc2 = (arg: (string | number)[]) => {
if (typeof arg[0] === 'string') return;
const abc: number = arg[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment