https://kotlinlang.org logo
#javascript
Title
# javascript
m

Mihai Voicescu

03/21/2023, 6:52 PM
Did anybody manage to make exporting an interface with enums as either Typescript Union or Enum (so that a Kotlin API project can be shared with a Typescript project)? Note that it has to survive serialization and deserialization... For example, given the following JSON:
Copy code
{ 
  "gender": "male"
  "age": 24
}
To be in Typescript:
Copy code
enum Gender {
Male = "male",
Female = "female"
}

interface Person {
gender: Gender
age: number
}
And in Kotlin:
Copy code
enum class Gender {
@SerialName("male")
Male,
@SerialName("female")
Female
}

interface Person {
gender: Gender
age: number
}
Note that I am using Kotlin Multiplatform
c

CLOVIS

03/22/2023, 10:32 AM
Have you looked at the
.d.ts
file generated by the compiler?
8 Views