Skip to content

Commit

Permalink
Merge pull request #61 from tyler-proofserve-com/extends
Browse files Browse the repository at this point in the history
add `extends` configuration variable
  • Loading branch information
gzuidhof authored Jul 20, 2024
2 parents 5d9a9b4 + b472dfd commit 1295fc3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ packages:
# in the output.
exclude_files:
- "private_stuff.go"

# Package that the generates Typescript types should extend. This is useful when
# attaching your types to a generic ORM.
extends: "SomeType"
```
See also the source file [tygo/config.go](./tygo/config.go).
Expand Down
3 changes: 3 additions & 0 deletions tygo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type PackageConfig struct {
// If "none" is supplied, no comments are preserved.
PreserveComments string `yaml:"preserve_comments"`

// Default interface for Typescript-generated interfaces to extend.
Extends string `yaml:"extends"`

// Set the optional type (null or undefined).
// Supported values: "default", "undefined" (same as "default"), "" (same as "default"), "null".
// Default is "undefined".
Expand Down
4 changes: 4 additions & 0 deletions tygo/write_toplevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func (g *PackageGenerator) writeTypeSpec(
if isStruct {
s.WriteString("export interface ")
s.WriteString(ts.Name.Name)
if g.conf.Extends != "" {
s.WriteString(" extends ")
s.WriteString(g.conf.Extends)
}

if ts.TypeParams != nil {
g.writeTypeParamsFields(s, ts.TypeParams.List)
Expand Down

0 comments on commit 1295fc3

Please sign in to comment.