-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(eslint): enable typescript-eslint/no-for-in-array #91420
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
Conversation
| if (shouldDelete) { | ||
| // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message | ||
| delete errorMessages[errorKey]; | ||
| delete errorMessages[errorKey as keyof typeof errorMessages]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I’m pretty sure this can’t have worked before. If we iterate with:
for (const errorKey in Object.keys(errorMessages))
errorKey will be the stringified index of the keys array, so ['0', '1'] etc. Then, going to the actual errorMessages object and deleting something at '0' doesn't do anything unless the key is literally the string '0'.
Maybe the intention was to do:
for (const errorKey in errorMessages)
to iterate over all keys?
@roggenkemper am I missing something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! i guess the case that it covered wasn't common enough to come up often.
JonasBa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see this might have also caught a bug in that loop. Approving the PR (provided @roggenkemper confirms this fixes a bug)
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #91420 +/- ##
==========================================
- Coverage 87.59% 87.59% -0.01%
==========================================
Files 10326 10326
Lines 586114 586100 -14
Branches 22618 22618
==========================================
- Hits 513417 513403 -14
Misses 72278 72278
Partials 419 419 |
While it’s legal to iterate over an array with
for-in, it’s likely not intended (for-in iterates over the properties of an Object) because it will return the index as a string, and has other room for bugs as stated here.Moving to
for-ofis a better fix in many places, as it will also rid us of no-null assertions when doing an indexed access.