I thought I had understood the concepts of Kotlin multiplatform and the hierarchy of source sets:
- Code that can be run on every platform goes into
commonMain, code that can only be run in the JVM goes into
- Also, declarations for which there are platform-specific implementations goes into
commonMain, while the implementations go into
- A large part of the Kotlin standard library can be used from
commonMainbecause there are implementations for JVM and JS.
- every declaration must be annotated with
@JsExport(assuming the IR backend)? Of course if it’s public I want to export it - otherwise I would have put it in
- even simple types like
These restrictions seem to undermine the elegant multiplatform model. Can someone please explain and also give a perspective on the future of these issues?
Now I’m even more baffled, because this works in a regular TypeScript project:
# Install the official Kotlin standard library npm install -save firstname.lastname@example.org # Install TypeScript definitions provided by a third party, # because for some unknown reason, the standard library # doesn't provide them npm install -save @email@example.com
import * as kotlinStdlibWrapper from "@mtm-solutions/kotlin-stdlib-wrapper" type List<T> = kotlinStdlibWrapper.kotlin.collections.List<T> const listOf = kotlinStdlibWrapper.kotlin.collections.listOf const list: List<string> = listOf(["a", "b"]) console.log(list.get(1)) // "b"
So it is obviously possible to use the