Skip to content

No compilation error on later declared variable referenceΒ #57694

@koleo9am

Description

@koleo9am

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions