Being opaque means that
- No matching javascript type
- It is not possible to create a value of this type from JavaScript (except if the
@JSExport ed constructor @JSExport ) - It is not possible to manipulate a value of this type (except for calls to
@JSExport ed methods and fields)
You can still get the value of this type from Scala.js code, pass it and return it to Scala.js code. You can also always call .toString() , because java.lang.Object.toString() is @JSExport ed. Other than toString() , neither Char nor Long export anything, so you cannot do anything with them.
Therefore, as you have already seen, JavaScript 1 cannot be used as Scala.js Long , because it does not have the right type. Also 'a' valid Char (but it is a valid String ).
Therefore, as you yourself assumed, you really should avoid opaque types and use other types instead if you need to create / manipulate them from JavaScript. The Scala.js side can convert back and forth using standard language tools such as someChar.toInt and someInt.toChar .
The choice of which type is best depends on your application. For Char it can be Int or String . For Long it could be a String , a pair of Int s, or perhaps even Double , if the possible values never use more than 52 bits of precision.
source share