Skip to main content

Lists

Primitive lists

A collection will get converted to array.

@Serializable
data class MyLists(
val strings: List<String>,
val ints: Set<Int>,
val longs: Collection<Long>,
)

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

You can get the full code here.

export interface MyLists {
strings: string[];
ints: number[];
longs: number[];
}

Lists of objects

@Serializable
data class Colour(
val rgb: String
)

@Serializable
data class MyLists(
val colours: List<Colour>,
val colourGroups: Set<List<Colour>>,
val colourGroupGroups: LinkedHashSet<List<List<Colour>>>,
)

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

You can get the full code here.

export interface MyLists {
colours: Colour[];
colourGroups: Colour[][];
colourGroupGroups: Colour[][][];
}

export interface Colour {
rgb: string;
}

Lists of collections

@Serializable
data class Colour(
val rgb: String
)

@Serializable
data class MyLists(
val listOfMaps: List<Map<String, Int>>,
val listOfColourMaps: List<Map<String, Colour>>,
)

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

You can get the full code here.

export interface MyLists {
listOfMaps: { [key: string]: number }[];
listOfColourMaps: { [key: string]: Colour }[];
}

export interface Colour {
rgb: string;
}