镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

for-of does not work with DOM collections when target is ES3 or ES5 #2696

Description

@Arnavion
var paragraphs = document.querySelectorAll("p");
for (let p of paragraphs) {
    console.log(p);
}
foo.ts(2,15): error TS2495: Type 'NodeList' is not an array type or a string type.

Is it because the standard emit will have the wrong behavior for live lists that are modified during iteration? A [].slice.call() in the emit would fix that, but perhaps that detracts from wanting to keep the output as close to the original as possible...

Activity

  1. mhegazy commented on Apr 9, 2015

    @mhegazy
    Contributor

    We did not want to complicate the array emit case, and did not want to do any type-directed emit. So for of only works on arrays for ES3/ES5.

  2. Arnavion commented on Apr 9, 2015

    @Arnavion
    ContributorAuthor

    Yep, makes sense. Thanks.

  3. emilgpa commented on Aug 26, 2015

    @emilgpa

    With core-js should work? I've tried but not work, with babel it works.

  4. added a commit that references this issue on Apr 10, 2017
  5. mhegazy commented on Apr 20, 2017

    @mhegazy
    Contributor

    Update on this issue, this should be addressed by #12346 under --downlevelIteration.

  6. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions