Next step in my Kotlin/JS journey, I would like to...
# javascript
s
Next step in my Kotlin/JS journey, I would like to be able to use https://www.npmjs.com/package/rsocket-websocket-client, so I have added
implementation(npm("rsocket-websocket-client", "0.0.16"))
dependency to my project and I would like to consume
RSocketWebSocketClient
class defined like that in JS:
Copy code
class RSocketWebSocketClient {
  constructor(options, encoders) {
    // ...
  }
  close() {
    // ...
  }
  connect() {
    // ...
  }
}
exports.default = RSocketWebSocketClient;
On Kotlin side, I have defined:
Copy code
@JsModule("rsocket-websocket-client")
external class RSocketWebSocketClient(options: dynamic, encoders: dynamic)

fun main() {
	println("Hello JavaScript!")
	RSocketWebSocketClient(js("{}"), js("{}"))
}
And I get this error
TypeError: RSocketWebSocketClient is not a constructor
. What did I miss?
It seems it works with:
Copy code
@file:JsModule("rsocket-websocket-client")

@JsName("default")
external class RSocketWebSocketClient()
I found this solution in https://stackoverflow.com/questions/51431848/how-to-import-node-module-in-react-kotlin, is this documented in the regular official documentation?
t
You can try using
dukat
to convert TypeScript types to kotlin external, it helped me with a lot of js modules
s
Thanks yes I know
dukat
but RSocket JS client is using Facebook Flow so I have to convert things manually