How to allow dynamic interface for a native JS trait in Scala 3?

38 views Asked by At

Following facade trait for three.js works fine with Scala 2:

@js.native
trait Uniforms extends js.Object with Dynamic {
  @JSBracketAccess
  def update(name: String, uniform: Uniform): Unit
  @JSBracketAccess
  def apply(name: String): Uniform

  @JSName("remove")
  def -=(name: String): Uniform

  @JSBracketAccess
  def selectDynamic(name: String): Uniform
  @JSBracketAccess
  def updateDynamic(name: String)(value: Uniform): Unit
}

It allows me to use uniforms both as u("opacity").value = 0.5 and u.opacity.value = 0.5.

The trouble is it does not work with Scala 3. It compiles fine, but it produces an error in while linking (fastOptJS):

[error] scala.Dynamic (of kind Interface) is not a valid interface implemented by threejs.Uniforms (of kind AbstractJSType)

[error] called from threejs.Uniforms

How can I define a facade for a native JS type in Scala 3 so that I can use it as Dynamic ? Deriving from js.Dynamic is not possible, as it is sealed.

0

There are 0 answers