I’m using a JS API that needs to be passed a Strin...
# javascript
n
I’m using a JS API that needs to be passed a String taken from a fixed set. I want to represent this with an enum in my Kotlin bindings. Is there a way to annotate an
enum class
to control how Kotlin will represent it to native JS code?
b
Not yet. It’s in our list of things that should be designed/improved.
workaround: declare in js
Copy code
var MyEnum = {
   foo: "foo",
   bar : "bar"
}
declare in Kotlin
Copy code
external sealed class MyEnum {
   object foo : MyEnum() {}
   object bar : MyEnum() {}
}
n
Should that be…
Copy code
external sealed class MyEnum {
    object foo : MyEnum() {}
    object bar : MyEnum() {}
}
?
b
oh, yes, of course
fixed