【问题标题】:How to suppress intellij IDEA error in editor when using Binding.scala macro annotation?使用 Binding.scala 宏注释时如何在编辑器中抑制 intellij IDEA 错误?
【发布时间】:2017-07-25 20:05:53
【问题描述】:

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

@dom def renderDiv: Binding[Div] = <div>...</div>

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

dom.render(document.getElementById("root"),renderDiv)

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

有什么解决办法吗?

【问题讨论】:

    标签: scala dom scala.js web-frontend binding.scala


    【解决方案1】:

    可以在范围内放置一个隐式转换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.")
    }
    

    在包对象中定义上述方法,从而覆盖整个包。实际上,这个方法永远不会被执行。

    【讨论】:

      猜你喜欢
      • 2013-02-12
      • 1970-01-01
      • 2014-04-18
      • 1970-01-01
      • 1970-01-01
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多