1

I am trying to iterate over options using val x = $(selectState).find("option").each((y: Element) => y). However Compilation throw following error.

type mismatch;
 found   : org.scalajs.dom.Element => org.scalajs.dom.Element
    (which expands to)  org.scalajs.dom.raw.Element => org.scalajs.dom.raw.Element
 required: scala.scalajs.js.|[scala.scalajs.js.ThisFunction0[org.scalajs.dom.Element,Any],scala.scalajs.js.ThisFunction1[org.scalajs.dom.Element,Int,Any]]
    (which expands to)  scala.scalajs.js.|[scala.scalajs.js.ThisFunction0[org.scalajs.dom.raw.Element,Any],scala.scalajs.js.ThisFunction1[org.scalajs.dom.raw.Element,Int,Any]]

I was referring to stack overflow question here.

Community
  • 1
  • 1
  • Which jQuery facade are you using and which version? – gzm0 Apr 06 '16 at 10:58
  • Based on the issue you raised in jquery-facade, I assume you're using that. It's odd -- I don't see offhand why that call to `each` isn't compiling. I'll try to look into that today, and see if I can figure out what's up. (Might be that the use of `|` is preventing the Scala function from implicitly converting to a JavaScript one, in which case I'll need to rewrite the facade for `each`.) – Justin du Coeur Apr 06 '16 at 12:04
  • I am using jquery-facade version 1.0-RC2 – Bhagyashree Apr 06 '16 at 12:14
  • Working on it now -- I've repro'ed the problem, and am confirming the cause... – Justin du Coeur Apr 06 '16 at 12:26

1 Answers1

0

Okay, answering this formally: yep, that was a bug in jquery-facade. Thanks for pointing it out!

The issue, as I suspected, was that the | type operator interferes with the compiler's ability to automatically cast Scala functions to JavaScript ones. So it wasn't understanding that (y: Element) => y (a Scala function) could be turned into a JavaScript js.Function0[Element, Any].

So I've split each into two separate overloads, one for each version, and that appears to work as desired. Please update to jquery-facade 1.0-RC3, and I think it should work for you.

Justin du Coeur
  • 2,699
  • 1
  • 14
  • 19