genovich
01/26/2025, 9:27 PMinterface X : () -> Unit
in KMP, then it leads to Implementing a function interface is prohibited in JavaScript.
I'm curious why?
On the other hand code like interface X: suspend () -> Unit
is compiling, but leads to runtime exception (TypeError: %field_name% is not a function
) in javascript when I'm trying to invoke such function, e.g.
interface X: suspend () -> Unit
suspend fun invoke(func: suspend () -> Unit) {
func.invoke() // fails here
}
invoke(XImpl())
However, if I replace invoke(XImpl())
with function reference invoke(XImpl()::invoke
then it is working as expected.
Thus I have two questions:
• Why are functional interfaces prohibited in JS?
• Is it possible to allow them or add a compile-time exception to suspend the inheritance of functions?
I'll be exceptionally grateful if you allow me to help you implement the fix.