Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No compilation error on later declared variable reference #57694

Closed
koleo9am opened this issue Mar 8, 2024 · 2 comments
Closed

No compilation error on later declared variable reference #57694

koleo9am opened this issue Mar 8, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@koleo9am
Copy link

koleo9am commented Mar 8, 2024

πŸ”Ž 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

@MartinJohns
Copy link
Contributor

Duplicate of #56827 / #11498.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 8, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants