Hi I am exploring Kotlin JS to leverage it to use ...
# javascript
k
Hi I am exploring Kotlin JS to leverage it to use Ktor Networking. I want to have a multiplatform library that provides repository layer to be shared across Android, iOS and JS platforms. In JS Platform I want to export repository interface from commonMain with @JsExport. And want jsMain to spit out TS definitions, so TS React apps can use it (seems like Dukat lib does this). I getting error when using "@JsExport" as it complains that it is not possible for suspend function so I'm write another wrapper interface in jsMain that returns Promise. Was wondering is this is right approach ? is there any reference projects that does this
a
Hi. For now days - yes. It is a right way. Also, if you want to export the class/interface without the "Not exportable declarations" then you could use @JsExport.Ignore.
Copy code
@JsExport
class MyClass(val myValue: String) {
  @JsExport.Ignore
  suspend fun someNotExportableDeclarations() = "Oops"
}
Also, some plugins could help you make such wrappers automatically. For example, this one, but it's still under development (the ball is on my side to find how to make lambda inside the plugin)
k
Thanks mate! will checkout your plugin