shadaj/slinky

Scala 3 onChange SyntheticEvent with unexpected higher kinds

evbo opened this issue · 0 comments

evbo commented

In Scala 2 for an input's onChange I would usually use a type like:
slinky.core.SyntheticEvent[org.scalajs.dom.html.Input, org.scalajs.dom.Event]

But in Scala 3 Slinky complains that it needs a:
slinky.core.SyntheticEvent[slinky.core.TagElement#RefType, org.scalajs.dom.Event]

[error]    |None of the overloaded alternatives of method := in object onChange with types
[error]    | (v: Option[() => Unit]): 
[error]    |  slinky.core.OptionalAttrPair[slinky.web.html._onChange_attr.type]
[error]    | (v: () => Unit): slinky.core.AttrPair[slinky.web.html._onChange_attr.type]
[error]    | [T <: slinky.core.TagElement]
[error]    |  (v: slinky.core.SyntheticEvent[T#RefType, org.scalajs.dom.Event] => Unit): 
[error]    |    slinky.core.AttrPair[T]
[error]    |match arguments ((setFiles : 
[error]    |  slinky.core.SyntheticEvent[org.scalajs.dom.html.Input, org.scalajs.dom.Event]
[error]    | => Unit))

But without referencing html.input you don't get target field.

And I can't think of a workaround at compile time. other than faking it so that I can at least compile to completion:

val onChange = useCallback(
  (ev: SyntheticEvent[TagElement#RefType, Event]) => {
    val ev1 = ev.asInstanceOf[slinky.core.SyntheticEvent[html.Input, org.scalajs.dom.Event]]
    println(s"Do stuff with: ${ev1.target.files}")
  }, 
  Seq()
)