@@ -190,14 +190,11 @@ func generateTSTypeInternal(rtype reflect.Type, tsTypesMap map[reflect.Type]stri
190190 }
191191 var isWaveObj bool
192192 if ! embedded {
193- buf .WriteString (fmt .Sprintf ("// %s\n " , rtype .String ()))
194193 if rtype .Implements (waveObjRType ) || reflect .PointerTo (rtype ).Implements (waveObjRType ) {
195194 isWaveObj = true
196- buf .WriteString (fmt .Sprintf ("type %s = WaveObj & {\n " , tsTypeName ))
197- } else {
198- buf .WriteString (fmt .Sprintf ("type %s = {\n " , tsTypeName ))
199195 }
200196 }
197+ var fieldsBuf bytes.Buffer
201198 var subTypes []reflect.Type
202199 for i := 0 ; i < rtype .NumField (); i ++ {
203200 field := rtype .Field (i )
@@ -206,7 +203,7 @@ func generateTSTypeInternal(rtype reflect.Type, tsTypesMap map[reflect.Type]stri
206203 }
207204 if field .Anonymous {
208205 embeddedBuf , embeddedTypes := generateTSTypeInternal (field .Type , tsTypesMap , true )
209- buf .WriteString (embeddedBuf )
206+ fieldsBuf .WriteString (embeddedBuf )
210207 subTypes = append (subTypes , embeddedTypes ... )
211208 continue
212209 }
@@ -226,7 +223,7 @@ func generateTSTypeInternal(rtype reflect.Type, tsTypesMap map[reflect.Type]stri
226223 if tsTypeTag == "-" {
227224 continue
228225 }
229- buf .WriteString (fmt .Sprintf (" %s%s: %s;\n " , fieldName , optMarker , tsTypeTag ))
226+ fieldsBuf .WriteString (fmt .Sprintf (" %s%s: %s;\n " , fieldName , optMarker , tsTypeTag ))
230227 continue
231228 }
232229 tsType , fieldSubTypes := TypeToTSType (field .Type , tsTypesMap )
@@ -237,10 +234,24 @@ func generateTSTypeInternal(rtype reflect.Type, tsTypesMap map[reflect.Type]stri
237234 if tsType == "UIContext" {
238235 optMarker = "?"
239236 }
240- buf .WriteString (fmt .Sprintf (" %s%s: %s;\n " , fieldName , optMarker , tsType ))
237+ fieldsBuf .WriteString (fmt .Sprintf (" %s%s: %s;\n " , fieldName , optMarker , tsType ))
241238 }
242239 if ! embedded {
243- buf .WriteString ("};\n " )
240+ buf .WriteString (fmt .Sprintf ("// %s\n " , rtype .String ()))
241+ if fieldsBuf .Len () == 0 && ! isWaveObj {
242+ // empty struct - use "object" instead of "{}" to satisfy linter
243+ buf .WriteString (fmt .Sprintf ("type %s = object;\n " , tsTypeName ))
244+ } else if isWaveObj {
245+ buf .WriteString (fmt .Sprintf ("type %s = WaveObj & {\n " , tsTypeName ))
246+ buf .Write (fieldsBuf .Bytes ())
247+ buf .WriteString ("};\n " )
248+ } else {
249+ buf .WriteString (fmt .Sprintf ("type %s = {\n " , tsTypeName ))
250+ buf .Write (fieldsBuf .Bytes ())
251+ buf .WriteString ("};\n " )
252+ }
253+ } else {
254+ buf .Write (fieldsBuf .Bytes ())
244255 }
245256 return buf .String (), subTypes
246257}
0 commit comments