使用Binding.scala宏注释时如何在编辑器中抑制intellij IDEA错误?

keo*_*eos 2 dom scala web-frontend scala.js binding.scala

尽管它在sbt控制台中编译并运行.Intellij抱怨我应该在编辑器中使用Binding [Node]而不是Elem.

@dom def renderDiv: Binding[Div] = <div>...</div>
Run Code Online (Sandbox Code Playgroud)

从intellij IDEA的角度来看,此方法返回的Elem是一个子类型scala.xml.Node,但在渲染时:

dom.render(document.getElementById("root"),renderDiv)
Run Code Online (Sandbox Code Playgroud)

它需要一个org.scalajs.dom.raw.Node.

这有什么解决方法吗?

keo*_*eos 6

可以在范围内放置隐式转换def:

package object xxx {
  implicit def makeIntellijHappy[T<:org.scalajs.dom.raw.Node](x: scala.xml.Node): Binding[T] =
    throw new AssertionError("This should never execute.")
}
Run Code Online (Sandbox Code Playgroud)

在包对象中定义上面的方法,因此它涵盖了整个包.实际上,此方法永远不会被执行.