Folks? is anybody consuming kotlin/native made lib...
# javascript
m
Folks? is anybody consuming kotlin/native made libraries from javascript/typescript projects? I've been reading, but I really could use a few pointers.
n
Are you referring to Kotlin JS or JS/TS? As far am I'm aware there isn't a system in place where there is bi-directional interop between Kotlin JS and Kotlin Native.
m
consuming a kotlin/native generated JS file from a separated JS/TS project. I want to ship a bunch of logic into several platforms at once, so kotlin perfectly fits the bill. The only problem is, I need to put the resultant JS files into several typescript projects, and I'm not really a JS guy.
n
Does Kotlin Native have the ability to generate a JS file? Are you talking about WASM?
m
kotlin does generate JS files, but I don't understand how to import them into other projects, or how to configure kotlin to make them more readable. I see modifiers like 'external' applied to Kotlin/Js files, but I don't get the purpose of them, for example
n
The external keyword ( https://kotlinlang.org/docs/reference/js-interop.html#external-modifier ) indicates which declaration (part of a JS API) can be consumed in Kotlin code.
b
You can consume js files generated from Kotlin as usual JS file/library. You can find more info here https://kotlinlang.org/docs/reference/js-to-kotlin-interop.html
By default kotlin compiler generates plain JS, but maybe if want you can configure it to use JS module system, any of AMD, CommonJS or UMD
And here you can find info about how to call JS from Kotlin: https://kotlinlang.org/docs/reference/js-interop.html
In addition — first message slightly confusing since Kotlin/Native is one of platform of Kotlin and you can’t use it (Kotlin/Native) to get JS (but you can get WASM with it). For JS we have Kotlin/JS 🙂
m
So if I want to create a javascript 'library' using common logic implemented in kotlin/native, I would need to create a kotlin/js integration layer in order to get a commonJS formatted file? So far I've been trying to import the kotlin/native generated file into a typescript to no avail
b
what do you mean by “common logic implemented in kotlin/native”?
There are one language — Kotlin and few backends(platforms), namely (JVM, JS and Native)
so if you need to target two or more backends(platforms) you should use multiplatform feature https://kotlinlang.org/docs/reference/multiplatform.html
👍 1