Skip to main content

Enums

Simple enum

@Serializable
enum class SomeType {
Alpha,
Beta,
Gamma
}

fun main() {
val tsGenerator = KxsTsGenerator()
println(tsGenerator.generate(SomeType.serializer()))
}

You can get the full code here.

export enum SomeType {
Alpha = "Alpha",
Beta = "Beta",
Gamma = "Gamma",
}

Enum with properties

Because enums are static, fields aren't converted.

@Serializable
enum class SomeType2(val coolName: String) {
Alpha("alpha") {
val extra: Long = 123L
},
Beta("be_beta"),
Gamma("gamma 3 3 3")
}

fun main() {
val tsGenerator = KxsTsGenerator()
println(tsGenerator.generate(SomeType2.serializer()))
}

You can get the full code here.

export enum SomeType2 {
Alpha = "Alpha",
Beta = "Beta",
Gamma = "Gamma",
}