Skip to content

Commit 462ebeb

Browse files
committed
Handle unknown types better
1 parent c62feeb commit 462ebeb

File tree

3 files changed

+241
-245
lines changed

3 files changed

+241
-245
lines changed

codersdk/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func readBodyAsError(res *http.Response) error {
114114
}
115115

116116
// Error represents an unaccepted or invalid request to the API.
117+
// @typescript-ignore Error
117118
type Error struct {
118119
httpapi.Response
119120

scripts/apitypings/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,15 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
367367
case "time.Time":
368368
// We really should come up with a standard for time.
369369
return TypescriptType{ValueType: "string"}, nil
370+
case "database/sql.NullTime":
371+
return TypescriptType{ValueType: "string", Optional: true}, nil
372+
case "github.com/google/uuid.NullUUID":
373+
return TypescriptType{ValueType: "string", Optional: true}, nil
370374
}
371375

372376
// If it's a struct, just use the name of the struct type
373377
if _, ok := n.Underlying().(*types.Struct); ok {
374-
return TypescriptType{ValueType: name, Comment: "Unknown named type, this might not work"}, nil
378+
return TypescriptType{ValueType: "any", Comment: fmt.Sprintf("Named type %q unknown, using \"any\"", n.String())}, nil
375379
}
376380

377381
// Defer to the underlying type.

0 commit comments

Comments
 (0)