@@ -13,14 +13,13 @@ import (
13
13
"strings"
14
14
"text/template"
15
15
16
- "github.com/coder/coder/coderd/util/slice"
17
-
18
16
"github.com/fatih/structtag"
19
17
"golang.org/x/tools/go/packages"
20
18
"golang.org/x/xerrors"
21
19
22
20
"cdr.dev/slog"
23
21
"cdr.dev/slog/sloggers/sloghuman"
22
+ "github.com/coder/coder/coderd/util/slice"
24
23
)
25
24
26
25
const (
@@ -511,14 +510,39 @@ func (g *Generator) buildStruct(obj types.Object, st *types.Struct) (string, err
511
510
return data .String (), nil
512
511
}
513
512
513
+ c := TypescriptType {
514
+ ValueType : "comparable" ,
515
+ GenericValue : "C" ,
516
+ GenericTypes : map [string ]string {
517
+ "C" :"comparable"
518
+ }
519
+ }
520
+
514
521
type TypescriptType struct {
515
- // GenericValue gives a unique character for mapping the value type
516
- // to a generic. This is only useful if you can use generic syntax.
517
- // This is optional, as the ValueType will have the correct constraints.
518
- GenericValue string
519
- // GenericTypes is a map of generic name to actual constraint
522
+ // GenericTypes is a map of generic name to actual constraint.
523
+ // We return these, so we can bubble them up if we are recursively traversing
524
+ // a nested structure. We duplicate these at the top level.
520
525
// Example: 'C = comparable'.
521
526
GenericTypes map [string ]string
527
+ // GenericValue is the value using the Generic name, rather than the constraint.
528
+ // This is only usedful if you can use the generic syntax. Things like maps
529
+ // don't currently support this, and will use the ValueType instead.
530
+ // Example:
531
+ // Given the Golang
532
+ // type Foo[C comparable] struct {
533
+ // Bar C
534
+ // }
535
+ // The field `Bar` will return:
536
+ // TypescriptType {
537
+ // ValueType: "comparable",
538
+ // GenericValue: "C",
539
+ // GenericTypes: map[string]string{
540
+ // "C":"comparable"
541
+ // }
542
+ // }
543
+ GenericValue string
544
+ // ValueType is the typescript value type. This is the actual type or
545
+ // generic constraint. This can **always** be used without special handling.
522
546
ValueType string
523
547
// AboveTypeLine lets you put whatever text you want above the typescript
524
548
// type line.
0 commit comments