@@ -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 ] {
@@ -434,7 +435,15 @@ func (g *Generator) buildStruct(obj types.Object, st *types.Struct) (string, err
434
435
valueType := tsType .ValueType
435
436
if tsType .GenericMapping != "" {
436
437
valueType = tsType .GenericMapping
437
- state .Generics = append (state .Generics , fmt .Sprintf ("%s extends %s" , tsType .GenericMapping , tsType .ValueType ))
438
+ // Don't add a generic twice
439
+ if _ , ok := genericsUsed [tsType .GenericMapping ]; ! ok {
440
+ // TODO: We should probably check that the generic mapping is
441
+ // not a different type. Like 'T' being referenced to 2 different
442
+ // constraints. I don't think this is possible though in valid
443
+ // go, so I'm going to ignore this for now.
444
+ state .Generics = append (state .Generics , fmt .Sprintf ("%s extends %s" , tsType .GenericMapping , tsType .ValueType ))
445
+ }
446
+ genericsUsed [tsType .GenericMapping ] = tsType .ValueType
438
447
}
439
448
state .Fields = append (state .Fields , fmt .Sprintf ("%sreadonly %s%s: %s" , indent , jsonName , optional , valueType ))
440
449
}
0 commit comments