I'm trying to export a Scala implementation of an algorithm for use in JavaScript. I'm using @JSExport
. The algorithm works with Scala Char
and Long
values which are marked as opaque in the interoperability guide.
I'd like to know (a) what this means; and (b) what the recommendation is for dealing with this.
I presume it means I should avoid Char
and Long
and work with String
plus a run-time check on length (or perhaps use a shapeless Sized
collection) and Int
instead.
But other ideas welcome.
More detail...
The kind of code I'm looking at is:
@JSExport("Foo")
class Foo(val x: Int) {
@JSExport("add")
def add(n: Int): Int = x+n
}
...which works just as expected: new Foo(1).add(2)
produces 3
.
Replacing the types with Long
the same call reports:
java.lang.ClassCastException: 1 is not an instance of scala.scalajs.runtime.RuntimeLong
(and something similar with methods that take and return Char
).