https://kotlinlang.org logo
#javascript
Title
# javascript
a

altavir

10/18/2023, 8:26 AM
Are there plans to return external enums in the future? This looks ugly:
Copy code
sealed external class DropEffects {
    @JsName("copy")
    object Copy : DropEffects

    @JsName("move")
    object Move : DropEffects

    @JsName("link")
    object Link : DropEffects

    @JsName("none")
    object None : DropEffects
}
t

turansky

10/18/2023, 12:36 PM
In most cases such unions are open in fact
As result - const enums (new feature) will solve only half of problem
a

altavir

10/18/2023, 12:37 PM
Idea suggests to use data objects. But obviously, you can't do that for external subclasses.
t

turansky

10/18/2023, 12:39 PM
In described example
objects
aren't required,
val
is fine
a

altavir

10/18/2023, 12:40 PM
You mean simple constants?
t

turansky

10/18/2023, 12:41 PM
Yes, like here
Copy code
sealed external interface Align {
    companion object {
        val TOP: Align
        val LEFT: Align
        val BOTTOM: Align
        val RIGHT: Align
    }
}
a

altavir

10/18/2023, 12:42 PM
I see
t

turansky

10/18/2023, 12:42 PM
We use objects only in case, when separate types are really required
One more example of constant
Which bonuses do you expect from enums in your case? Short declaration only?
a

altavir

10/18/2023, 2:06 PM
yes
t

turansky

10/18/2023, 2:16 PM
DropEffects
in your example - string union emulation?
a

altavir

10/18/2023, 2:16 PM
Yes. In this particular case, I think string constants will do. But it is an import from TS.