Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Fixes errors when generating TypeScript components #2605

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/view/tsgen/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,16 @@ func (c *Converter) visit(w *gostrings.Builder, t reflect.Type, depth int) ([]st
}
componentNames = append(componentNames, names...)
case reflect.Map:
var keyString string = t.Key().String()
switch keyString {
// typing for validation steps causes errors with reflection, so we just lock string keys.
case "component.FormValidator":
keyString = "string"
}

// if a map is found, key the key and element to build a typescript object definition.
w.WriteString("{[key:" + t.Key().String() + "]:")
w.WriteString("{[key:" + keyString + "]:")

names, err := c.visit(w, t.Elem(), depth+1)
if err != nil {
return nil, err
Expand Down
10 changes: 6 additions & 4 deletions pkg/view/tsgen/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ func (c Component) Referenced() []ImportReference {

var refs []ImportReference
for _, r := range list {
refs = append(refs, ImportReference{
Name: r,
ImportName: strcase.KebabCase(r),
})
if c.Name != r { // Prevent nested/recursive component imports
refs = append(refs, ImportReference{
Name: r,
ImportName: strcase.KebabCase(r),
})
}
}

return refs
Expand Down
2 changes: 1 addition & 1 deletion pkg/view/tsgen/tsgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (tg *TSGen) Reflect(names []string) (*Model, error) {

m := &Model{}
if err := gob.NewDecoder(&stdout).Decode(m); err != nil {
return nil, fmt.Errorf("decode reflet model: %w", err)
return nil, fmt.Errorf("decode reflect model: %w", err)
}

return m, nil
Expand Down