andylamax
02/13/2022, 5:26 AM1.6.20-M1
for the kotlin team. Please upvote and lets see if we can get it on 1.6.20
it looks like they are currently focusing on @JsExport
at the moment
This is a feature request on how companion objects of classes and interfaces should behave in kotlin/js stricly when marked with @JsExport
Current Status
1. Marking an interface that has a companion object with @JsExport
fails the build. You can get it to work with Suppress("WRONG_EXPORTED_DECLARATION")
but this leads to incorrect typescript definition generations (static getter on the interface)
2. Marking an external class that has a companion with @JsExport
fails the build even with Suppress("WRONG_EXPORTED_DECLARATION")
. I am assuming this is even why currently kotlin.js.Promise
is not marked as @JsExport
Breakdown
1. External interfaces with companion objects do not make any sense, from Kotlin and even Typescript. So @JsExport
on external interfaces should definitely not compile
2. non external interfaces that have a companion object and are marked with @JsExport
should definitely compile. Because they have meaning at least in Kotlin. Especially when used in multiplatform context. As in I can create an interface in common code, have some members in its companion object then decide to export it. Many KMP devs use this pattern
3. external classes (abstract, open, final) with companion objects should definitely be compillable because they have a solid one to one correlation between Kotlin and Typescript
Proposal
1. interfaces marked with @JsExport
should work as they are now. Only difference is when it comes to type definitions, everything found inside and including the companion object itself should just be skipped during generation of types.
2. external classes (abstract, open, final) with companion objects should definitely be exportable. I am surprised as to why the compiler currently fails to compile them
Metadata
Kotlin: 1.6.20-M1
Ticket: https://youtrack.jetbrains.com/issue/KT-51292turansky
02/13/2022, 1:17 PMnamespace
required for fine solutions or @JsStatic
turansky
02/13/2022, 1:20 PMcompanion
can be single solution in case of externalsandylamax
02/13/2022, 1:30 PMAchifal
07/01/2022, 12:50 PMandylamax
07/02/2022, 3:40 AMbuildSrc
turansky
07/02/2022, 1:15 PMandylamax
07/02/2022, 1:17 PMandylamax
07/02/2022, 1:17 PMandylamax
07/02/2022, 1:20 PMAchifal
07/04/2022, 2:32 PM