We are migrating one of our mobile codebase (alrea...
# javascript
m
We are migrating one of our mobile codebase (already in production) to kotlin 1.4M to support Typescript and provide a JS implementation. However we have some issues regarding the new IR backend and @JSExport. Here are some questions: Is there a way for @JsExport to export transitive dependencies ? The following code produce an error:
Copy code
@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:
Copy code
@JsExport
object A {
  var b: String = ""
}
The following TypeScript definition is generated:
Copy code
/* ErrorDeclaration: Class A with kind: OBJECT */
Is there any workaround for this? Is there any plan to support those types?
👀 3
a
^ cc @Svyatoslav Kuzmich [JB]
s
Is 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).
m
Thanks a lot for your quick answers. Will adapt things on our side!
a
hm, we currently use quite a few Factories in our JS code like
object 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?
s
j
Adding to this thread: It seems I can’t use
@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?