So I've got an externally defined interface with a...
# webassembly
m
So I've got an externally defined interface with a function on it. That function takes a callback function, but
wasmJs
keeps crying that I'm using
Unit
. Is there any way around this?
Copy code
@JsName("EventEmitter")
internal external interface JsEventEmitter {
    fun on(
        event: String,
        listener: Function<Unit>,
    ): JsEventEmitter
}
Copy code
Type 'Function<Unit>' cannot be used as value parameter type of JS interop function. Only external, primitive, string, and function types are supported in Kotlin/Wasm JS interop.
r
As far as I know you have to use
() -> Unit
instead
👀 1
m
That worked, thanks!
Copy code
@JsName("EventEmitter")
internal external interface JsEventEmitter {
    fun <T: JsAny?> on(
        event: String,
        listener: (T) -> Unit,
    ): JsEventEmitter
}
t
Is it Node.js
EventEmitter
?
m
Yes
Boom.
wasmJs
support added to kmp-process
t
1. We plan to provide Node.js declarations for WasmJS in this issue 2. Kotlin/JS EventEmitter you can find here 3. Static
on
supports cancellation
m
Yep. I am aware. My libraries will never use those dependencies.
t
Is it common restriction for external dependencies?
m
Yes, I try to limit dependencies to only what is absolutely necessary. As it relates to Js/WasmJs, I only need a few external definitions, so.
👍 1