andy
11/04/2022, 7:24 PM@JsExport
on export declarations that use List<>
.
For example, we have many data classes like this:
data class Line(val points = List<Point>)
data class Point(val x: Double, val y: Double)
It’s not possible to use @JsExport
in this case.
There seems to be no good workaround for this. Switching to Array
causes problems for iOS because List
gets exposed as an NSArray
and Array
does not, and besides it would require us to implement hashCode()
manually for the data class. We could add an extension method to the jsMain
source set to access the list as a JS Array, but we’d need to suppress the compiler warnings and it seems like extension methods aren’t supported well with JS/IR either.
I’m wondering, would it be too difficult to add @JsExport
to List
and related collection methods in the standard library? It would be fine if points
in the above example is exposed to Javascript as a List
class transpiled from Kotlin as long as it had some basic interface available from the JS side (size
, get
and toArray()
or toJsArray()
would be fine). Just wondering if this is on the roadmap, or if it is something that could be done as an external contribution (perhaps by us)? Any other ideas of how to workaround this problem if not?andylamax
11/04/2022, 8:58 PMBig Chungus
11/04/2022, 10:18 PMagrosner
11/05/2022, 1:08 PMJohn Huang
04/03/2023, 9:13 PMandylamax
04/04/2023, 6:18 PMJohn Huang
04/04/2023, 7:17 PMJohn Huang
04/27/2023, 5:29 PMimport kollections
gives Unresolved reference: kollections
andylamax
04/27/2023, 6:43 PMandylamax
04/28/2023, 10:35 AM