Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
Scalajs, js.Dictionary inconsistent behavior

I have an inconsistent error using ScalaJS. Here is a minimal example: the size and the content of a dictionary variable are inconsistent.


def A(mapping: js.Dictionary[String]): Unit = {
  dom.console.log(mapping)
  dom.console.log(mapping.size)
}

I link the IRs using fastOptJS. In the driver code in html, I have

const colorSetting = new Map([
        ["1", "black"]
]);
ScalaJSExample.A(colorSetting)

In the console, the first line prints the content of the variable correctly,

"Map {"1" => "black"}"

but the second line prints 0. I have also tried to swap the position of the two lines, but the result is the same. Any methods such as .foreach or the for (x <- mapping) all treat the variable mapping as empty.

Any suggestion why this is the case? I am using Scala 2.12.8, ScalaJS 1.7.1.

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

A js.Dictionary represents a POJO (plain old JavaScript object) where elements are fields. But you are passing a JS new Map() to it, which is not a POJO--it's a Map. The correct type to represent a JS Map is js.Map.

Either pass a dictionary to ScalaJSExample.A, as follows:

const colorSetting = {
    "1": "black"
};
ScalaJSExample.A(colorSetting)

or declare mapping as a js.Map in the Scala.js code:

def A(mapping: js.Map[String, String]): Unit = {
  dom.console.log(mapping)
  dom.console.log(mapping.size)
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda