In WebView, using Map is not possible.

未关闭
#56,924 10 条评论 3 个 reaction 已指派 1 人 在 GitHub 查看

@rbuckton 已经在做这个了。

开始于 2024年1月3日。

评估

这个 Issue 还没有评估数据。

描述

Needs Investigation
🔎 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

主要语言
Go
星标
111k
派生
14.4k
平均合并
1 天 19 小时
30 天内合并 PR
117

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/TypeScript 的其他 Issue

查看 microsoft/TypeScript 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。