Skip to content

Commit

Permalink
Merge pull request #37 from foomo/fix/ts-scalar-union-definition
Browse files Browse the repository at this point in the history
fix: change scalar union type rendering
  • Loading branch information
franklinkim committed Jul 17, 2023
2 parents 1837e9b + e46893a commit 31ed425
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,23 @@ func renderTypescriptStruct(str *Struct, mappings config.TypeScriptMappings, sca
}
ts.nl()
case str.UnionFields[0].Value.Scalar != nil:
ts.app("export const " + str.Name + " = ")
ts.app("{ ")
for i, field := range str.UnionFields {
if i > 0 {
ts.app(", ")
}
ts.app("...")
field.Value.tsType(mappings, scalars, structs, ts, &JSONInfo{OmitEmpty: true})
}
ts.app(" }")
ts.nl()
ts.app("export type " + str.Name + " = ")
for i, field := range str.UnionFields {
if i > 0 {
ts.app(" & ")
ts.app(" | ")
}
ts.app("(typeof ")
field.Value.tsType(mappings, scalars, structs, ts, &JSONInfo{OmitEmpty: true})
ts.app(")")
}
ts.nl()
default:
Expand Down

0 comments on commit 31ed425

Please sign in to comment.