Explicit extension method literals?


#1

When calling

jq().click({e -> })

I get:

None of the following functions can be called with the arguments supplied:
internal final fun click() : js.jquery.JQuery defined in js.jquery.JQuery
internal final fun click(handler : js.dom.core.Element.(js.jquery.MouseClickEvent) -> Unit) : js.jquery.JQuery defined in js.jquery.JQuery
Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) => …} notation

But the only way I can define the required lambda is to use this long-hand:

val f: Element.(MouseClickEvent) -> Unit = {e -> }
jq().click(f)

Is there something shorter (or at least doesn’t require a separate statement)?


#2

Looks like a bug. Please, report to the tracker


#3

Done: http://youtrack.jetbrains.com/issue/KT-2435

BTW I assume you mean the bug is with the type inference.

But let’s say that the type inference here were harder (say there was another overload that took a similar function, but with a different parameter or return type).  Is there a shorter way to explicitly write the extension method literal, syntactically speaking?

I.e., any workaround for me in the meantime?


#4

You can write an extension function literal in-place:

``

jq().click {Element.(e: MouseClickEvent) -> …}