π Search Terms
variable reference foreach before declaration
π Version & Regression Information
- This is the behavior in every version available on Playground
β― Playground Link
https://www.typescriptlang.org/play?ts=5.4.2#code/MYewdgzgLgBADjAXDaAnAlmA5gbQLowC8MOA5AKYAeAhgLZwA25peA3AFBwB0AZiKgFFqwABYAKSkQB8MAN7sYMdDxgTC6ygEo5CxTACeXOAFcI42QF9NHRRfZWOoSLH1ESbIA
π» Code
const p = [];
p.forEach(x => {
if (x===x) {
y.push({});
}
});
const y = [];
π Actual behavior
Usage of y in foreeach doesn't lead to compilation error. But it produces a runtime error.
π Expected behavior
Compilation error on line y.push({});
Additional information about the issue
No response