Skip to content

Commit a0fed88

Browse files
committed
Add more comments
1 parent cf16160 commit a0fed88

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

scripts/apitypings/main.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import (
1313
"strings"
1414
"text/template"
1515

16-
"github.com/coder/coder/coderd/util/slice"
17-
1816
"github.com/fatih/structtag"
1917
"golang.org/x/tools/go/packages"
2018
"golang.org/x/xerrors"
2119

2220
"cdr.dev/slog"
2321
"cdr.dev/slog/sloggers/sloghuman"
22+
"github.com/coder/coder/coderd/util/slice"
2423
)
2524

2625
const (
@@ -511,14 +510,39 @@ func (g *Generator) buildStruct(obj types.Object, st *types.Struct) (string, err
511510
return data.String(), nil
512511
}
513512

513+
c := TypescriptType {
514+
ValueType: "comparable",
515+
GenericValue: "C",
516+
GenericTypes: map[string]string{
517+
"C":"comparable"
518+
}
519+
}
520+
514521
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.
520525
// Example: 'C = comparable'.
521526
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.
522546
ValueType string
523547
// AboveTypeLine lets you put whatever text you want above the typescript
524548
// type line.

0 commit comments

Comments
 (0)