microsoft / microsoft/TypeScript

In WebView, using Map is not possible.

Open
#56,924 10 comments 3 reactions 1 assignee View on GitHub

@rbuckton is already working on this.

Since Jan 3, 2024.

Needs Investigation
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms

"iterator", "iterable", "Map", "WebView"

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about __values.
⏯ Playground Link

No response

💻 Code
// Your code here
🙁 Actual behavior

I am using RN with a WebView, and the web application uses class-validator. I encountered an error stating 'Object is not iterable.' Upon investigation, I found that the issue comes from the transformation of for...of loops to __values in esm5. (the original code is here)

The class-validator uses Map and it does not have the property length. And in WebView the m is undefined in the following compiled __values. Hence the error is shown.

var __values = (this && this.__values) || function(o) {
    // here, o is from the return value of Map instance's entries.
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};

So, I fix this issue like following temporarily.

var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    if (o.next) return o; // add this line
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};

This issue occurs not only with Map but also when using Set in WebView.

🙂 Expected behavior

I can use Map and Set in WebView.

Additional information about the issue

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.