is there a list of transpiling limitations/workaro...
# javascript
g
is there a list of transpiling limitations/workarounds for .kt to .js? It looks like standard enums aren’t well supported yet.
s
I’m not sure if there is such a list. Searching for unresolved YouTrack issues would be the closest thing I know https://youtrack.jetbrains.com/issues/KT?q=Subsystems:%20%7BBackend.%20JS%7D%20%23Bug%20%23Problem%20%23Unresolved%20
What kind of problems are you encountering with enums?
g
I can refer to specific members of an enum but when I try to use the enum class statically (er, by class name?), the compiler complains because it doesn’t have a companion object. Not sure how to refer to the enum class generally. Still learning here.
Classifier 'PresetType' does not have a companion object, and thus must be initialized here
Copy code
PresetType.values()
outputs an array without keynames, and broken fields.
Seems like maybe I should be using the serializer instead of just transpiling.
s
Oh, this error message is not very explanatory. But I believe you would get the same error on other Kotlin platforms. You would generally use enum class name as a type and enum entries names as values. Or do you have a specific use-case of using class name as a value?
g
I’m just in discovery of how we move some of our shared semantics into a common tier. we have a java rest service and a legacy angular app that I’m writing an adapter for — we use basic java enums a lot, and our client representations use a lot of enumeration. I kinda expected an enum to serialize like a companion object does. will have to learn more here.
s
Copy code
PresetType.values().map { it.name }
should produce a list of names. Is it broken for you?
t
@glade Looks like
PresetType
is
external
enum, isn't it?
s
external enums have known problems with
.values()
but regular enums should work fine
g
No, the enum is defined in Kotlin. I’m looking to export its representation for existing legacy javascript, not write more kotlin code that gets transpiled against that model.