Hello. I’ve written an SDK with KMM and been worki...
# multiplatform
p
Hello. I’ve written an SDK with KMM and been working on it and used on an iOS and an Android project. It’s all good now. Now, the client wants me to have the same SDK be compatible with JS. Now I’m researching and was able to somehow build it for JS. But when I attempt to do
@JSExport
on underlying classes with suspend functions, I can’t. it gives me:
Copy code
Declaration of such kind (suspend function) can't be exported to JS
Now I’m confused. I’m using Kotlin 1.7.2, btw. Do I need to convert ALL, as in ALL, of the Suspend functions into Promise?
a
I’ve been looking into a similar problem, and as I understand it, yes, you can’t
@JsExport
suspend functions https://youtrack.jetbrains.com/issue/KT-56281/KJS-Cant-export-suspend-functions
e
you can export wrapper functions that expose
kotlin.js.Promise
a
there’s a related thread https://kotlinlang.slack.com/archives/C0B8L3U69/p1687814822369679, which mentions a WIP compiler plugin that is aiming to automatically generate functions that return
Promise<>
https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin
p
Thank you for your responses. Sadly my sdk is built with suspend functions, and I will have to do a couple of overhauls to “wrap” the functions into promises without affecting the iOS and android ones. but thanks Adam S for that link, that could potentially lessen my work. Otherwise, I’ll have to do it myself then.
x
@JSExport
is super limited (and has been for years) unfortunately 😞