Support Enum Companion
@KustomExport
enum class E {
EnumValue;
companion object {
val static = 1
}
}
generates
@JsExport
public class E internal constructor(
internal val common: CommonE,
) {
public val name: String = common.name
}
@JsExport
public fun E_values(): Array<E> = arrayOf(E_EnumValue, E_Companion)
@JsExport
public fun E_valueOf(name: String): E? {
if (name == E_EnumValue.name)
return E_EnumValue
if (name == E_Companion.name)
return E_Companion
return null
}
public fun E.importE(): CommonE = common
public fun CommonE.exportE(): E = E_valueOf(this.name)!!
@JsExport
public val E_EnumValue: E = E(CommonE.EnumValue)
@JsExport
public val E_Companion: E = E(CommonE.Companion)
which is an error because Type mismatch: inferred type is E.Companion but E was expected in the last line. The incorrect assumption is made that the companion object is an enum value.
Workaround: Use JsExport instead of KustomExport
I don't think this will be supported: KustomExport goal was to provide enum support in older Kotlin version, now that newest Kotlin supports it, it's more than advised to use JsExport (unfortunately there's no doc saying that today). Using KustomExport on an enum is only adding more code to your js bundle, passthrough code so possible performance impact and the exposed syntax is not the Kotlin one.
I may remove the enum support completely in a future version.
That's a fair point but wouldn't KustomExport still provide better functionality in some cases? For example if you want to have a property of type List in the enum.
It could but I believe some simple workarounds can be found, it's a matter of trade-off so some may need it. As I don't use this tool myself anymore I won't be able to spend time on it on a foreseeable future, feel free to open a PR if you want this feature though.