xored / scala-js-react

ScalaJS interface for Facebook React
Apache License 2.0
133 stars 13 forks source link

Compilation error #16

Closed freewind closed 9 years ago

freewind commented 9 years ago

Following code will cause compilation error:

case class Props(projects: Seq[Project], onSelectProject: (Project) => Unit)

@scalax
  override def render(self: This) = {
    <div>
      {self.props.projects.map(p => <div onClick={self.props.onSelectProject(p)}>{p.name}</div>)}
    </div>
  }

and Project:

case class Project(name: String, links: Seq[Link], description: Option[String] = None)
case class Link(name: String, url: String, description: Option[String] = None)

Error:

2. Waiting for source changes... (press enter to interrupt)
[info] Compiling 1 Scala source to /Users/twer/workspace/wind-links/target/scala-2.11/classes...
[error] /Users/twer/workspace/wind-links/src/main/scala/in/freewind/windlinks/pages/config/ProjectLists.scala:22: overloaded method value apply with alternatives:
[error]   (key: String,value: scala.scalajs.js.Dynamic,md: scala.scalajs.js.Dictionary[scala.scalajs.js.Any])scala.scalajs.js.Dictionary[scala.scalajs.js.Any] <and>
[error]   [T](key: String, value: scala.scalajs.js.Dictionary[T], md: scala.scalajs.js.Dictionary[scala.scalajs.js.Any])scala.scalajs.js.Dictionary[scala.scalajs.js.Any] <and>
[error]   [T](key: String, value: Map[String,T], md: scala.scalajs.js.Dictionary[scala.scalajs.js.Any])scala.scalajs.js.Dictionary[scala.scalajs.js.Any] <and>
[error]   (key: String,value: Double,md: scala.scalajs.js.Dictionary[scala.scalajs.js.Any])scala.scalajs.js.Dictionary[scala.scalajs.js.Any] <and>
[error]   (key: String,value: Boolean,md: scala.scalajs.js.Dictionary[scala.scalajs.js.Any])scala.scalajs.js.Dictionary[scala.scalajs.js.Any] <and>
[error]   (key: String,value: String,md: scala.scalajs.js.Dictionary[scala.scalajs.js.Any])scala.scalajs.js.Dictionary[scala.scalajs.js.Any] <and>
[error]   (key: String,value: Function3[_, _, _, _],md: scala.scalajs.js.Dictionary[scala.scalajs.js.Any])scala.scalajs.js.Dictionary[scala.scalajs.js.Any] <and>
[error]   (key: String,value: Function2[_, _, _],md: scala.scalajs.js.Dictionary[scala.scalajs.js.Any])scala.scalajs.js.Dictionary[scala.scalajs.js.Any] <and>
[error]   (key: String,value: Function1[_, _],md: scala.scalajs.js.Dictionary[scala.scalajs.js.Any])scala.scalajs.js.Dictionary[scala.scalajs.js.Any] <and>
[error]   (key: String,value: Function0[_],md: scala.scalajs.js.Dictionary[scala.scalajs.js.Any])scala.scalajs.js.Dictionary[scala.scalajs.js.Any] <and>
[error]   (key: String,value: Option[Function1[_, _]],md: scala.scalajs.js.Dictionary[scala.scalajs.js.Any])scala.scalajs.js.Dictionary[scala.scalajs.js.Any]
[error]  cannot be applied to (String, Unit, scala.scalajs.js.Dictionary[scala.scalajs.js.Any])
[error]   @scalax
[error]    ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 1 s, completed Feb 14, 2015 12:36:53 PM
3. Waiting for source changes... (press enter to interrupt)

But if I remove the onClick={self.props.onSelectProject(p)} part, it will be OK.

Is it because the parameter p is not a normal type like string, but a custom complex type Project?

kanterov commented 9 years ago

This is because you supplied onClick with value of type Unit, while it expects to take Function, so solution is to write () => self.props.onSelectProject(p), I have idea how we could improve compiler error messages, it would be implemented in 0.4.0.

freewind commented 9 years ago

Thanks, I know how to fix it

freewind commented 9 years ago

And this is really a great project, thanks for making it!