Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSMacro should support union types #70

Open
mariussoutier opened this issue Feb 26, 2016 · 6 comments
Open

JSMacro should support union types #70

mariussoutier opened this issue Feb 26, 2016 · 6 comments

Comments

@mariussoutier
Copy link

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
@mariussoutier mariussoutier changed the title JSMacro doesn't support union types JSMacro should support union types Feb 26, 2016
@chandu0101
Copy link
Owner

@mariussoutier
Copy link
Author

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...

@oyvindberg
Copy link
Collaborator

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 scala-js/scala-js#2070 for details), but you can easily provide your own. Or cast yourself, like you figured out.

Would @sjrd have any idea, perhaps?

@mariussoutier
Copy link
Author

What do you mean, it's not safe?

@oyvindberg
Copy link
Collaborator

safe as in, you can get runtime exceptions

@mariussoutier
Copy link
Author

Thanks. Then I'll use my internal version for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants