Skip to main content

Basic classes

Plain class with a single field

@Serializable
class Color(val rgb: Int)

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

You can get the full code here.

export interface Color {
rgb: number;
}

Plain class with primitive fields

@Serializable
class SimpleTypes(
val aString: String,
var anInt: Int,
val aDouble: Double,
val bool: Boolean,
private val privateMember: String,
)

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

You can get the full code here.

export interface SimpleTypes {
aString: string;
anInt: number;
aDouble: number;
bool: boolean;
privateMember: string;
}

Data class with primitive fields

@Serializable
data class SomeDataClass(
val aString: String,
var anInt: Int,
val aDouble: Double,
val bool: Boolean,
private val privateMember: String,
)

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

You can get the full code here.

export interface SomeDataClass {
aString: string;
anInt: number;
aDouble: number;
bool: boolean;
privateMember: string;
}