Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala 3 onChange SyntheticEvent with unexpected higher kinds #593

Open
evbo opened this issue Sep 11, 2022 · 0 comments
Open

Scala 3 onChange SyntheticEvent with unexpected higher kinds #593

evbo opened this issue Sep 11, 2022 · 0 comments

Comments

@evbo
Copy link

evbo commented Sep 11, 2022

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()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants