TypeScript Version: 4.0.2
Search Terms:
flow type narrowing loop
Code
for (let p: number | string = 1; p; p = p + 1) {
// Just make sure for iterator is reachable
if (p) {
continue
}
// Actually unreachable here
// Comment this line out, everything works correctly
break
}
Expected behavior:
No errors. p is typed number in p = p + 1
Actual behavior:
p is number | string
Playground Link: https://www.typescriptlang.org/zh/play?target=1#code/GYewTgBAFANgpgFwgBwFwQHYFcC2AjOSAHwgGcEwBLDAcwgF4IBGAbhTeQZQgGpmBKCAG8AsACgIkiJWDRkg0RKnKAxiAwJqWOOOUBfXVID0RiAEEVCLAEMYMAJ4QsGMHGsqAFtbzwIHwjpiAJB4rtYA1uJ6QA
TypeScript Version: 4.0.2
Search Terms:
flow type narrowing loop
Code
Expected behavior:
No errors. p is typed number in
p = p + 1Actual behavior:
p is number | string
Playground Link: https://www.typescriptlang.org/zh/play?target=1#code/GYewTgBAFANgpgFwgBwFwQHYFcC2AjOSAHwgGcEwBLDAcwgF4IBGAbhTeQZQgGpmBKCAG8AsACgIkiJWDRkg0RKnKAxiAwJqWOOOUBfXVID0RiAEEVCLAEMYMAJ4QsGMHGsqAFtbzwIHwjpiAJB4rtYA1uJ6QA