Skip to content

Instantly share code, notes, and snippets.

@sjrd
Last active September 9, 2016 13:27
Show Gist options
  • Save sjrd/6dc54785b831c099cb43e3ec761db7ad to your computer and use it in GitHub Desktop.
Save sjrd/6dc54785b831c099cb43e3ec761db7ad to your computer and use it in GitHub Desktop.
Scala 2.12.0-RC1's new inference improves JS interop!
package helloworld
import scala.scalajs.js
import js.|
import js.annotation._
@ScalaJSDefined
trait Foo extends js.Object {
val bar: Int | String
val baz: js.UndefOr[Int]
val f: js.Function1[Int, Int]
}
@ScalaJSDefined
class Foobar extends Foo {
val bar = 5
val baz = 6
val f = (x: Int) => x + 1
}
object HelloWorld extends js.JSApp {
def main() {
val foobar: Foo = new Foobar
println(foobar.bar)
println(foobar.baz)
println(foobar.f)
println(foobar.f(3))
val obj = new Foo {
val bar = "hello"
val baz = js.undefined
val f = x => x * 2
}
println(obj.bar)
println(obj.baz)
println(obj.f)
println(obj.f(3))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment