In WebView, using Map is not possible.

Abierto
#56,924 10 comentarios 3 reacciones 1 asignado Ver en GitHub

@rbuckton ya está trabajando en esto.

Desde el 3/1/2024.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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

Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/TypeScript

Todos los issues de microsoft/TypeScript

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.