Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Docs: Deprecateno-for-in-array #10558

Closed as not planned
Closed as not planned
Labels
documentationDocumentation ("docs") that needs adding/updatinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.triageWaiting for team members to take a lookwontfixThis will not be worked on
@kirkwaiblinger

Description

@kirkwaiblinger

Before You File a Documentation Request Please Confirm You Have Done The Following...

Suggested Changes

I'm wondering ifno-for-in-array should be deprecated in favor of a trivial syntactic ban onForInStatement in all cases.

For ordinary objects,for...in has pitfalls, too: see core ruleguard-for-in.Object.keys() is widely supported and addresses this use case.

For ordinary arrays, i.e.for (const k in ["a", "b", "c"]) {}, the statement works just fine and iterates over the indices as expected (EDIT: *except for holes). Even though the indices are string-keyed,TS appears to have syntactic special-casing to allow indexing in this case. So the rule isn't really helping here.

For regex arrays, which are mentioned as a motivation for the rule,the rule doesn't even report.

constreArray=/fe/.exec('foo')!;for(constreArrayKeyinreArray){console.log(reArray[reArrayKey])}

Taken together, it seems like

  • we're not reporting where we really should
  • where we do report, it's not so clear we even need to
  • therefore, we're not really making very good use of type information
  • and a syntactic total ban offor...in makes more sense to me anyway, since there aren't any common scenarios in which you'dwantfor...in, and don't have a straightforward alternative to it.

The one argument I see against this is thatfor...inseems to be the only way to get enumerable inherited properties (EDIT: other thanmanually iterating the prototype chain). To which I'd say, if you need to do that for some reason, and know that you need to, then you probably are comfortable disabling eslint rules.

Affected URL(s)

https://typescript-eslint.io/rules/no-for-in-array/

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationDocumentation ("docs") that needs adding/updatinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.triageWaiting for team members to take a lookwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp