Enforce `Event => Unit` Event handlers
oyvindberg opened this issue · 2 comments
oyvindberg commented
Wouldn't it be better if we enforced that event handlers return Unit
?
That is change this:
var onmousedown: js.Function1[MouseEvent, _] = js.native
to this:
var onmousedown: js.Function1[MouseEvent, Unit] = js.native
If you agree i can for sure throw up a PR with the necessary changes
lihaoyi commented
I don't remember why I did this initially, but IIRC there was some odd interaction which made type-inference sad if i made it have an explicit Unit
. @sjrd do you remember?
sjrd commented
It would be worse. The Any/_
result type is better. It allows to use a lambda that returns anything, not only lambdas that return Unit
. This is similar to how foreach
in the Scala collections accepts functions that return anything.