-
Notifications
You must be signed in to change notification settings - Fork 887
prefer-for-of rule recommended on a node list #2927
Comments
It is specified as Also note that core-js can polyfill iterators for most DOM collections, including NodeList. If you need to be "safe" and avoid iterating on them directly, you could also wrap the |
@Kovensky do you run a specific tsconfig that allows TypeScript to do this or are you suggesting to request it as an issue for them? My comment about it not being supported was based off of the MDN Specifications that state "forEach on NodeList is NOT a part of any standard". Maybe I'm misunderstanding that though. |
@Kovensky It is iterable with ES6 support or with --downlevelIterators flag in TypeScript. I had to remove this rule due to this false positive. |
@brandyscarney says: > here are the ones I ran into issues with in the framework: > > * `no-unnecessary-type-assertion` is throwing errors when we cast as an HTMLElement - which is necessary because otherwise it queries as an `Element` and throws errors that the properties don’t exist, this is a bug in TS: palantir/tslint#3540 > * `prefer-for-of` is throwing errors on node lists which is also a bug: palantir/tslint#2927 > * `no-conditional-assignment` is used in DOM controller
Duplicate of #2021. |
Bug Report
TypeScript code being linted
with
tslint.json
configuration:Actual behavior
Receiving the error "Expected a 'for-of' loop instead of a 'for' loop with this simple iteration (prefer-for-of)
Expected behavior
A for of loop to my knowledge shouldn't be used on a NodeList as it's not supported widely & is also not part of any standard. TypeScript will complain if you do this. The same with a forEach loop.
The text was updated successfully, but these errors were encountered: