File tree Expand file tree Collapse file tree 1 file changed +25
-9
lines changed Expand file tree Collapse file tree 1 file changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -6,20 +6,29 @@ Create TypeScript interfaces from Kotlinx Serialization classes.
6
6
7
7
``` kotlin
8
8
@Serializable
9
- data class PlayerDetails (
10
- val name : String ,
11
- val health : Float ,
9
+ class MyClass (
10
+ val aString : String ,
11
+ var anInt : Int ,
12
+ val aDouble : Double ,
13
+ val bool : Boolean ,
14
+ private val privateMember : String ,
12
15
)
13
16
14
- println (
15
- KxsTsGenerator ().generate(Color .serializer())
16
- )
17
+ fun main () {
18
+ val tsGenerator = KxsTsGenerator ()
19
+ println (tsGenerator.generate(MyClass .serializer()))
20
+ }
17
21
```
18
22
23
+ Generated TypeScript interface:
24
+
19
25
``` typescript
20
- interface PlayerDetails {
21
- name: string ;
22
- health: number ;
26
+ export interface MyClass {
27
+ aString: string ;
28
+ anInt: number ;
29
+ aDouble: number ;
30
+ bool: boolean ;
31
+ privateMember: string ;
23
32
}
24
33
```
25
34
@@ -30,6 +39,13 @@ The Kotlinx Serialization API should be used to generate TypeScript. The
30
39
[ ` SerialDescriptor ` s] ( https://kotlin.github.io/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.descriptors/-serial-descriptor/index.html )
31
40
are flexible and comprehensive enough to allow for accurate TypeScript code, without any deviation.
32
41
42
+ The aim is to create TypeScript interfaces that can accurately produce Kotlinx Serialization
43
+ compatible JSON.
44
+
45
+ The Kotlinx Serialization API should be used to generate TypeScript. The
46
+ [ ` SerialDescriptor ` s] ( https://kotlin.github.io/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.descriptors/-serial-descriptor/index.html )
47
+ are flexible and comprehensive enough to allow for accurate TypeScript code, without any deviation.
48
+
33
49
See [ the docs] ( ./docs ) for working examples.
34
50
35
51
## Status
You can’t perform that action at this time.
0 commit comments