Skip to content

adamko-dev/kotlinx-serialization-typescript-generator

Repository files navigation

Kotlinx Serialization TypeScript Generator

Create TypeScript interfaces from Kotlinx Serialization classes.

@Serializable
data class PlayerDetails(
  val name: String,
  val health: Float,
)

println(
  KxsTsGenerator().generate(Color.serializer())
)
interface PlayerDetails {
  name: string;
  health: number;
}

The aim is to create TypeScript interfaces that can accurately produce JSON that Kotlinx Serialization can parse.

See the docs for working examples.

Status

This is a proof-of-concept.

Status Notes
Basic classes example
Nullable and default-value properties example
Value classes example
Enums example
Lists example
Maps ✅/⚠ example Maps with complex keys are converted to an ES6 Map. See
Polymorphism - Sealed classes ✅/⚠ example Nested sealed classes are ignored
Polymorphism - Open classes example Not implemented. Converted to type MyClass = any
Edge cases - circular dependencies example