[go: up one dir, main page]

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

In-line callbacks in for..of loops have access to the iteration variable #2693

Open
R-unic opened this issue May 17, 2024 · 3 comments
Open

Comments

@R-unic
Copy link
R-unic commented May 17, 2024
public setColor(color: Color3): void {
    for (const child of this.instance.GetChildren().filter((i): i is Frame => child.IsA("Frame")))
      child.BackgroundColor3 = color;
  }

In this instance an error should be thrown because the object being iterated is referencing the iteration variable in the callback for filter. This compiles with no error on roblox-ts@2.3.0.

This example also comes from me refactoring and forgetting to change child to i, and it went unnoticed until it errored in game.

@Dionysusnu
Copy link
Contributor

Roblox-ts doesn't have control over type or scope checking behaviour, we leave it up to Typescript. You can see in this playground example how it allows similar unintuitive behaviour, which errors in JS as well.

@R-unic
Copy link
Author
R-unic commented May 17, 2024

very bizarre. you'd think there'd be some way to circumvent this when compiling though

@Dionysusnu
Copy link
Contributor
Dionysusnu commented May 17, 2024

I haven't been able to find any cases where this doesn't error in JS, so I wonder if this would count as a reasonably-fixable-bug on the TypeScript side. You could try making an issue there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants