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

Fix for key: T, value in loop to define value using typed key #1564

Merged
merged 1 commit into from
Nov 3, 2024

Conversation

edemaine
Copy link
Collaborator

@edemaine edemaine commented Nov 2, 2024

Helps with #1562

Before:

for x: T, y in z
  console.log x, y
---
for (const key in z) {const x: T = key;const y = z[key];
  console.log(x, y)
}

After:

for x: T, y in z
  console.log x, y
---
for (const key in z) {const x: T = key;const y = z[x];
  console.log(x, y)
}

This allows us to manually fix the type of the key to keyof typeof z, for example, which helps get the right type for y.

@edemaine edemaine merged commit b628945 into main Nov 3, 2024
4 checks passed
@edemaine edemaine deleted the for-in-type branch November 3, 2024 12:35
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

Successfully merging this pull request may close these issues.

2 participants