Martin Gagnon
05/20/2020, 2:10 PM@JsExport
data class A(val b: String) {
companion object
}
e: java.lang.AssertionError: Properties without fields are not supported A.Companion_instance
Also, when using the @JsExport
annotation on an object
, example:
@JsExport
object A {
var b: String = ""
}
The following TypeScript definition is generated:
/* ErrorDeclaration: Class A with kind: OBJECT */
Is there any workaround for this? Is there any plan to support those types?anton.bannykh
05/20/2020, 2:21 PMSvyatoslav Kuzmich [JB]
05/20/2020, 2:24 PMIs there a way for @JsExport to export transitive dependencies ?No. Our current plan is to require explicit export. The reason is that only a subset of Kotlin can be sanely represented in JS and implicit export can start reporting errors in places far from the place you made an edit, or inside a code you don’t own.
Is there any workaround for this? Is there any plan to support those types?We are working on supporting object export, including companions. Unfortunately, I don’t think there is a workaround other than not using objects (for example using class + property instance instead).
Martin Gagnon
05/20/2020, 4:47 PMankushg
05/22/2020, 1:24 AMobject FooFactory { fun createFoo(param1: A, param2: B): Foo }
because it lets us deal with potential dynamic inputs avoid worrying about overloaded constructors when JS is only going to use one of them
Is there a ticket I can follow for updates on object export?Svyatoslav Kuzmich [JB]
05/22/2020, 6:22 AMJustin
05/24/2020, 9:23 PM@JsExport
on any class that is also annotated with @Serializable
because (I’m presuming) kotlinx.serialization
auto-generates a companion object for classes marked as such.
That’ll be a deal-breaker for me if there’s no workaround since we need that serialization lib.
https://kotlinlang.slack.com/archives/C0B8L3U69/p1590354711300900?thread_ts=1590348596.293700&cid=C0B8L3U69
Any ideas?