Hi! I am playing with 1.4-M3 and noticed that `@Js...
# javascript
n
Hi! I am playing with 1.4-M3 and noticed that
@JsExport
is actually quite restrictive. I am wondering whether there are any plans to relax this in the future? I am mostly thinking supporting enums and properties without fields. At the moment I cannot export a class annotated with
@Serializable
. The specific use case is sharing a data class between my TS and Kotlin/jvm codebases Otherwise amazing work with 1.4, it's amazing to have TS definitions for kotlin code
j
https://youtrack.jetbrains.com/issue/KT-39740 and https://youtrack.jetbrains.com/issue/KT-37829 the second issue should fix the first issue i believe and it's being worked on i believe not sure about the enums, would love JsExport on Enums as well
n
Thanks for linking the issues, I didn't find them on my own. This does sound like the kind of thing that hopefully will be there for 1.4.x
The use case with
@Serializable
is not very niche either
j
i'm abandoning @Serializable now, since it's making my generated JS enormous
n
how are you serialising in kotlin/js what alternatives are there?
j
i'm busy figuring that out now on the JS side this is working, just need to get it type safe
Copy code
console.log(JSON.stringify(json("email" to state.email)))
on the JVM side it's easy, just use Jackson or Gson
using that VS serializable is a difference of 17kB VS 349kB (post minify, before running external minifier and compactor, it's over 700kB)
n
fair enough! have you considered kotlinx serialization through reflection a la gson? Is that a thing outside of the jvm
It would get you rid of the extra generated code and of having to write stuff outside of the common source set but idk if it's a thing in mpp
j
now you just need something like this so that JS and JVM uses different serialization
Copy code
expect fun RegisterState.toJson(): String
expect fun RegisterState.fromJson(value: String)
i didn't know you could switch on reflection, do you have a link where i can read more ?
They do use reflection but still need to have annotated your classes
j
the issue for me is filesize, so if i'm switching to one of the others, my filesize will be even bigger guess i'll be sticking to my handrolled serializer for now, the JS is about a factor 10-20x smaller in the end
n
yeah fair enough! thanks for the info
t
Possibly you don't need classes, but contracts :)
j
contracts is a decent alternative for enums
t
In common - possibility to have clear JS API (without Kotlin classes in *.d.ts)
d
Is there an issue being tracked for supporting enums with @JsExport ?
🤞 1
👀 1