Hello everyone! We're interested in using Kotlin/...
# javascript
m
Hello everyone! We're interested in using Kotlin/Multiplatform to build an SDK that can be used by external applications in JVM and JS environments. However, it looks like the generated Javascript isn't really usable from non-Kotlin JS environments and doesn't seem like it was designed to. Using the IR compiler, the limits placed on what can be exported (no suspend functions being the big one but the others are pretty close behind) make it impossible to write well-designed code, and the format of the exports make it difficult to write good code on the consumer side. The Legacy compiler is equally problematic due to the lack of TS definitions and the ever-spooky "Legacy" word. Is using Kotlin/Multiplatform with a JS target with the express purpose of building a library that can be consumed from TS a use case that will be better supported in the future? Thanks for your time!
s
FYI that we use a JS library produced through a KMP project in a react JS app that loads through websites. In production. With reasonable amount of active users.
Pure JS would be similar experience. TS support is there but there may be more surprises around it with something not working as expected
So it really depends on your use case/product whether you can get a reasonably good JS library from a KMP project or not. There are gotchas but still doable.
m
The JS output from the legacy compiler does seem like it would work well enough, but we need to consume the library from TS so we have to use the IR compiler. The restrictions on exports, like no
suspend
functions and no
expect
classes showing up in method signatures makes it hard to develop the library in a sensible way. I've updated the original post to restrict the question to TS specifically. Thanks for the help!
a
I build some compiler tool based on Kotlin MPP, and integrate its JS outcome into my vscode extension. It is based on JSIR. https://github.com/atsushieno/mugene-ng/tree/main/mugene-project
well, looks like your question is specific to usability as TS. Maybe it's not that helpful answer then, I don't really depend on the d.ts output...