scalajs-react-components
scalajs-react-components copied to clipboard
JSMacro should support union types
When using union types, one must cast to js.Any, e.g.:
case class Pie(padding: js.UndefOr[Double | Shape] = js.undefined) {
def toJs = {
val p = js.Dynamic.literal()
padding.foreach(x => p.updateDynamic("padding")(x.asInstanceOf[js.Any]))
p
}
}
JSMacro doesn't know about this, so this compiler error comes up:
type mismatch;
found : scala.scalajs.js.|[Double,Shape]
required: scala.scalajs.js.Any
hey you need this import
import chandu0101.scalajs.react.components._
https://github.com/chandu0101/scalajs-react-components/blob/master/core/src/main/scala/chandu0101/scalajs/react/components/package.scala#L16
Ah thanks.
The import is package private, so I can't use it for my own stuff. I copied the code, but it produces strange errors in Play that it can't find its config files...
I'm not sure what to do about this. The implicit that we use is not safe in the general case, which is why we no longer export it (see https://github.com/scala-js/scala-js/pull/2070 for details), but you can easily provide your own. Or cast yourself, like you figured out.
Would @sjrd have any idea, perhaps?
What do you mean, it's not safe?
safe as in, you can get runtime exceptions
Thanks. Then I'll use my internal version for now.