@@ -66,6 +66,41 @@ export type Double = double; // assume that 'double' will be provided by another
66
66
67
67
<!-- - TEST TS_COMPILE_OFF -->
68
68
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
+
69
104
### Override nullable elements
70
105
71
106
Even though UInt is nullable, it should be overridden by the UInt defined in ` descriptorOverrides ` .
@@ -82,6 +117,7 @@ data class ItemHolder(
82
117
@Serializable
83
118
data class Item (
84
119
val count : UInt? = 0u ,
120
+ val score : Int? = 0 ,
85
121
)
86
122
87
123
fun main () {
@@ -93,12 +129,14 @@ fun main() {
93
129
typeRef = TsTypeRef .Declaration (id = TsElementId (" uint" ), parent = null , nullable = false )
94
130
)
95
131
132
+ tsGenerator.descriptorOverrides + = Int .serializer().descriptor to TsLiteral .Custom (" customInt" )
133
+
96
134
println (tsGenerator.generate(ItemHolder .serializer()))
97
135
}
98
136
99
137
```
100
138
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 ) .
102
140
103
141
``` typescript
104
142
export interface ItemHolder {
@@ -107,6 +145,7 @@ export interface ItemHolder {
107
145
108
146
export interface Item {
109
147
count? : UInt | null ;
148
+ score? : customInt | null ;
110
149
}
111
150
112
151
export type UInt = uint ;
@@ -129,15 +168,21 @@ import dev.adamko.kxstsgen.core.*
129
168
@JvmInline
130
169
value class Tick (val value : UInt )
131
170
171
+ @Serializable
172
+ @JvmInline
173
+ value class Phase (val value : Int )
174
+
132
175
@Serializable
133
176
data class ItemHolder (
134
177
val item : Item ,
135
178
val tick : Tick ? ,
179
+ val phase : Phase ? ,
136
180
)
137
181
138
182
@Serializable
139
183
data class Item (
140
184
val count : UInt? = 0u ,
185
+ val score : Int? = 0 ,
141
186
)
142
187
143
188
fun main () {
@@ -149,26 +194,32 @@ fun main() {
149
194
typeRef = TsTypeRef .Declaration (id = TsElementId (" uint" ), parent = null , nullable = false )
150
195
)
151
196
197
+ tsGenerator.descriptorOverrides + = Int .serializer().descriptor to TsLiteral .Custom (" customInt" )
198
+
152
199
println (tsGenerator.generate(ItemHolder .serializer()))
153
200
}
154
201
155
202
156
203
```
157
204
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 ) .
159
206
160
207
``` typescript
161
208
export interface ItemHolder {
162
209
item: Item ;
163
210
tick: Tick | null ;
211
+ phase: Phase | null ;
164
212
}
165
213
166
214
export interface Item {
167
215
count? : UInt | null ;
216
+ score? : customInt | null ;
168
217
}
169
218
170
219
export type Tick = UInt ;
171
220
221
+ export type Phase = customInt ;
222
+
172
223
export type UInt = uint ;
173
224
```
174
225
0 commit comments