Skip to content

Commit

Permalink
Tweak typescript templates
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Jun 13, 2024
1 parent 9182737 commit 400dd01
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tools/cmd/gen-types/types.ts.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { encodeAs } from "../encoding";
{{ define "objectify"}}
this.{{lcName .Name}} &&
{{- if .Repeatable -}}
this.{{lcName .Name}}?.map(v => {{objectify . "v"}})
this.{{lcName .Name}}?.map(v => v == undefined ? undefined : {{objectify . "v"}})
{{- else}}
{{objectify . (print "this." (lcName .Name))}}
{{- end}}
Expand Down
6 changes: 3 additions & 3 deletions tools/cmd/gen-types/typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TsNeedsCtor(typ *Type) bool {
func TsResolveType(field *Field) string {
typ := field.Type.TypescriptType(false)
if field.Repeatable {
typ = typ + "[]"
typ = "(" + typ + " | undefined)[]"
}
return typ
}
Expand All @@ -84,7 +84,7 @@ func TsInputType(field *Field) string {
typ = field.Type.TypescriptInputType(false)
}
if field.Repeatable {
typ = "(" + typ + ")[]"
typ = "(" + typ + " | undefined)[]"
}
return typ
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func TsUnobjectify(field *Field, varName string) string {
return tsUnobjectify2(field, varName)
}

return fmt.Sprintf("%s.map(v => %s)", varName, tsUnobjectify2(field, "v"))
return fmt.Sprintf("%s.map(v => v == undefined ? undefined : %s)", varName, tsUnobjectify2(field, "v"))
}

func tsUnobjectify2(field *Field, varName string) string {
Expand Down

0 comments on commit 400dd01

Please sign in to comment.