Skip to content

Latest commit

 

History

History
108 lines (80 loc) · 1.59 KB

File metadata and controls

108 lines (80 loc) · 1.59 KB

Edge cases

Demonstrations of how edge cases are handled.

Recursive references

A references B which references A which references B... should be handled properly

Classes

@Serializable
class A(val b: B)

@Serializable
class B(val a: A)

fun main() {
  val tsGenerator = KxsTsGenerator()
  println(tsGenerator.generate(A.serializer(), B.serializer()))
}

You can get the full code here.

export interface A {
  b: B;
}

export interface B {
  a: A;
}

Lists

@Serializable
class A(
  val list: List<B>
)

@Serializable
class B(
  val list: List<A>
)

fun main() {
  val tsGenerator = KxsTsGenerator()
  println(tsGenerator.generate(A.serializer(), B.serializer()))
}

You can get the full code here.

export interface A {
  list: B[];
}

export interface B {
  list: A[];
}

Map

@Serializable
class A(
  val map: Map<String, B>
)

@Serializable
class B(
  val map: Map<String, A>
)

fun main() {
  val tsGenerator = KxsTsGenerator()
  println(tsGenerator.generate(A.serializer(), B.serializer()))
}

You can get the full code here.

export interface A {
  map: { [key: string]: B };
}

export interface B {
  map: { [key: string]: A };
}