Hello Everyone, I am working with a kmp library fo...
# javascript
r
Hello Everyone, I am working with a kmp library for network calls which can be used with android,ios and js. When I am building js package, now the classes which are there in common mode are not getting exported and because of this we can not use it in javascript. can anyone help please? here is my js configuration in build.gradle js(IR) { browser { webpackTask { output.libraryTarget = “this” } binaries.executable() } }
a
You need to use @JsExport annotation to mark those declarations that would be used from JavaScript side. More here: https://kotlinlang.org/docs/js-to-kotlin-interop.html#jsexport-annotation https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-js-export/ For collections the documentation will be updated, because they are exportable since 2.0 (I believe, that you already can use them in 2.0.0-RC1)
r
@Artem Kobzar can’t it export suspend functions? as api calls are implemented using suspend method so is there any way to export so that same can work in javascript.
a
No, for exporting suspend functions you need to create a wrapper with
asPromise
and if it is inside an exported class, you need to annotate the method as
@JsExport.Ignore
Also, there is a plugin that can generate such wrappers, but I don't know how it works with the @JsExport annotation
r
ok
The plugin I mentioned
r
sure. Thanks @Artem Kobzar I will check
e
Just keep in mind you'll have to reason about coroutine scopes when exporting your code. Using GlobalScope isn't ideal.
r
sure