Skip to content

Commit c4c0ddb

Browse files
committed
Merge branch 'master' of https://github.com/OneOfOne/struct2ts
* 'master' of https://github.com/OneOfOne/struct2ts: export interfaces inline
2 parents e7d4d71 + 2c27bcd commit c4c0ddb

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

s2ts.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (s *StructToTS) RenderTo(w io.Writer) (err error) {
170170
io.WriteString(w, "\n")
171171
}
172172

173-
io.WriteString(w, "// classes\n")
173+
io.WriteString(w, "// structs\n")
174174
for _, st := range s.structs {
175175
if err = st.RenderTo(s.opts, buf); err != nil {
176176
return
@@ -186,6 +186,11 @@ func (s *StructToTS) RenderTo(w io.Writer) (err error) {
186186
}
187187

188188
func (s *StructToTS) RenderExports(w io.Writer) (err error) {
189+
if s.opts.InterfaceOnly && s.opts.NoHelpers {
190+
// nothing else to export
191+
return nil
192+
}
193+
189194
io.WriteString(w, "// exports\n")
190195

191196
export := func(n string) { _, err = fmt.Fprintf(w, "%s%s,\n", s.opts.indents[1], n) }
@@ -196,8 +201,11 @@ func (s *StructToTS) RenderExports(w io.Writer) (err error) {
196201
io.WriteString(w, "export {\n")
197202
}
198203

199-
for _, st := range s.structs {
200-
export(st.Name)
204+
// interfaces are exported inline!
205+
if !s.opts.InterfaceOnly {
206+
for _, st := range s.structs {
207+
export(st.Name)
208+
}
201209
}
202210

203211
if !s.opts.NoHelpers {

struct.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ func (s *Struct) RenderTo(opts *Options, w io.Writer) (err error) {
3131
if opts.ES6 { // no interfaces in js
3232
return
3333
}
34+
if !opts.NoExports {
35+
fmt.Fprintf(w, "export ")
36+
}
3437
_, err = fmt.Fprintf(w, "interface %s {\n", s.Name)
3538
} else {
3639
_, err = fmt.Fprintf(w, "class %s {\n", s.Name)

0 commit comments

Comments
 (0)