@@ -370,6 +370,7 @@ func (g *Generator) buildStruct(obj types.Object, st *types.Struct) (string, err
370
370
state .Extends = strings .Join (extends , ", " )
371
371
}
372
372
373
+ genericsUsed := make (map [string ]string )
373
374
// For each field in the struct, we print 1 line of the typescript interface
374
375
for i := 0 ; i < st .NumFields (); i ++ {
375
376
if extendedFields [i ] {
@@ -438,7 +439,15 @@ func (g *Generator) buildStruct(obj types.Object, st *types.Struct) (string, err
438
439
valueType := tsType .ValueType
439
440
if tsType .GenericMapping != "" {
440
441
valueType = tsType .GenericMapping
441
- state .Generics = append (state .Generics , fmt .Sprintf ("%s extends %s" , tsType .GenericMapping , tsType .ValueType ))
442
+ // Don't add a generic twice
443
+ if _ , ok := genericsUsed [tsType .GenericMapping ]; ! ok {
444
+ // TODO: We should probably check that the generic mapping is
445
+ // not a different type. Like 'T' being referenced to 2 different
446
+ // constraints. I don't think this is possible though in valid
447
+ // go, so I'm going to ignore this for now.
448
+ state .Generics = append (state .Generics , fmt .Sprintf ("%s extends %s" , tsType .GenericMapping , tsType .ValueType ))
449
+ }
450
+ genericsUsed [tsType .GenericMapping ] = tsType .ValueType
442
451
}
443
452
state .Fields = append (state .Fields , fmt .Sprintf ("%sreadonly %s%s: %s" , indent , jsonName , optional , valueType ))
444
453
}
0 commit comments