Kalalau Cantrell

03/24/2023, 1:22 PM
Hey all, new to KMP and exploring the feasibility of creating a shared lib that can be used across iOS, Android, and web (TS + React). My specific question is how are people working around the limitation where
can’t be exported with
? With my limited experience in KMP, see below for something I’ve cobbled together that’s been working but it does not seem ideal. For instance, converting to and from
and having to create wrappers for every collection type takes away from the dream of writing business logic once at a high level and reusing it across platforms. Does anyone have advice for doing this in perhaps a more generic way? Has anyone found a way to use
expect / actual
as a better solution?
class PeopleList : MutableList<StarWarsPerson> by mutableListOf() {
    fun toArray(): Array<StarWarsPerson> {
        val array = emptyArray<StarWarsPerson>()
        this.forEachIndexed { index, person ->
            array[index] = person
        return array

    companion object {
        fun fromArray(people: Array<StarWarsPerson>): PeopleList {
            val peopleList = PeopleList()
            return peopleList

data class StarWarsPerson(val name: String

Big Chungus

03/24/2023, 1:42 PM
Create your expect/actual list wrapper that is external interface on js and encapsulates array, while being regular interface encapsulating list on other platforms
Then you can @JsExport js actual
If you need to construct them from common,make some builder functions via expect actual too

Kalalau Cantrell

03/24/2023, 2:19 PM
Thanks for the tips! I’ll give this a shot.


03/25/2023, 10:43 AM
See also as a possible alternative to

Seth Madison

04/21/2023, 4:04 AM
FWW, we are shipping a JS/Android/Apple lib and ended up just using
internally and externally. The performance hit you take in JS for using a
is staggering. We’re hoping to adopt when it is ready.