@@ -66,6 +66,41 @@ export type Double = double; // assume that 'double' will be provided by another
6666
6767<!-- - TEST TS_COMPILE_OFF -->
6868
69+ Instead of changing the output to be a type alias, a custom 'literal' type can be set instead.
70+
71+ ``` kotlin
72+ import kotlinx.serialization.builtins.serializer
73+ import dev.adamko.kxstsgen.core.*
74+
75+ @Serializable
76+ data class Item (
77+ val price : Double ,
78+ val count : Int ,
79+ )
80+
81+ fun main () {
82+ val tsGenerator = KxsTsGenerator ()
83+
84+ tsGenerator.descriptorOverrides + =
85+ Double .serializer().descriptor to TsLiteral .Custom (" customDouble" )
86+
87+ println (tsGenerator.generate(Item .serializer()))
88+ }
89+ ```
90+
91+ > You can get the full code [ here] ( ./code/example/example-customising-output-02.kt ) .
92+
93+ This produces no type alias, and ` Double ` is overridden to be ` customDouble ` .
94+
95+ ``` typescript
96+ export interface Item {
97+ price: customDouble ;
98+ count: number ;
99+ }
100+ ```
101+
102+ <!-- - TEST TS_COMPILE_OFF -->
103+
69104### Override nullable elements
70105
71106Even though UInt is nullable, it should be overridden by the UInt defined in ` descriptorOverrides ` .
@@ -82,6 +117,7 @@ data class ItemHolder(
82117@Serializable
83118data class Item (
84119 val count : UInt? = 0u ,
120+ val score : Int? = 0 ,
85121)
86122
87123fun main () {
@@ -93,12 +129,14 @@ fun main() {
93129 typeRef = TsTypeRef .Declaration (id = TsElementId (" uint" ), parent = null , nullable = false )
94130 )
95131
132+ tsGenerator.descriptorOverrides + = Int .serializer().descriptor to TsLiteral .Custom (" customInt" )
133+
96134 println (tsGenerator.generate(ItemHolder .serializer()))
97135}
98136
99137```
100138
101- > You can get the full code [ here] ( ./code/example/example-customising-output-02 .kt ) .
139+ > You can get the full code [ here] ( ./code/example/example-customising-output-03 .kt ) .
102140
103141``` typescript
104142export interface ItemHolder {
@@ -107,6 +145,7 @@ export interface ItemHolder {
107145
108146export interface Item {
109147 count? : UInt | null ;
148+ score? : customInt | null ;
110149}
111150
112151export type UInt = uint ;
@@ -129,15 +168,21 @@ import dev.adamko.kxstsgen.core.*
129168@JvmInline
130169value class Tick (val value : UInt )
131170
171+ @Serializable
172+ @JvmInline
173+ value class Phase (val value : Int )
174+
132175@Serializable
133176data class ItemHolder (
134177 val item : Item ,
135178 val tick : Tick ? ,
179+ val phase : Phase ? ,
136180)
137181
138182@Serializable
139183data class Item (
140184 val count : UInt? = 0u ,
185+ val score : Int? = 0 ,
141186)
142187
143188fun main () {
@@ -149,26 +194,32 @@ fun main() {
149194 typeRef = TsTypeRef .Declaration (id = TsElementId (" uint" ), parent = null , nullable = false )
150195 )
151196
197+ tsGenerator.descriptorOverrides + = Int .serializer().descriptor to TsLiteral .Custom (" customInt" )
198+
152199 println (tsGenerator.generate(ItemHolder .serializer()))
153200}
154201
155202
156203```
157204
158- > You can get the full code [ here] ( ./code/example/example-customising-output-03 .kt ) .
205+ > You can get the full code [ here] ( ./code/example/example-customising-output-04 .kt ) .
159206
160207``` typescript
161208export interface ItemHolder {
162209 item: Item ;
163210 tick: Tick | null ;
211+ phase: Phase | null ;
164212}
165213
166214export interface Item {
167215 count? : UInt | null ;
216+ score? : customInt | null ;
168217}
169218
170219export type Tick = UInt ;
171220
221+ export type Phase = customInt ;
222+
172223export type UInt = uint ;
173224```
174225
0 commit comments