|
39 | 39 | // CLI option types:
|
40 | 40 | "github.com/coder/serpent",
|
41 | 41 | }
|
42 |
| - indent = " " |
| 42 | + indent = "\t" |
43 | 43 | )
|
44 | 44 |
|
45 | 45 | func main() {
|
@@ -646,7 +646,7 @@ func (g *Generator) buildStruct(obj types.Object, st *types.Struct) (string, err
|
646 | 646 | // Just append these as fields. We should fix this later.
|
647 | 647 | state.Fields = append(state.Fields, tsType.AboveTypeLine)
|
648 | 648 | }
|
649 |
| - state.Fields = append(state.Fields, fmt.Sprintf("%sreadonly %s%s: %s", indent, jsonName, optional, valueType)) |
| 649 | + state.Fields = append(state.Fields, fmt.Sprintf("%sreadonly %s%s: %s;", indent, jsonName, optional, valueType)) |
650 | 650 | }
|
651 | 651 |
|
652 | 652 | // This is implemented to ensure the correct order of generics on the
|
@@ -759,12 +759,8 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
|
759 | 759 | // }
|
760 | 760 | // }
|
761 | 761 | return TypescriptType{
|
762 |
| - ValueType: "any", |
763 |
| - AboveTypeLine: fmt.Sprintf("%s\n%s", |
764 |
| - indentedComment("Embedded anonymous struct, please fix by naming it"), |
765 |
| - // Linter needs to be disabled here, or else it will complain about the "any" type. |
766 |
| - indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- Anonymously embedded struct"), |
767 |
| - ), |
| 762 | + ValueType: "unknown", |
| 763 | + AboveTypeLine: indentedComment("Embedded anonymous struct, please fix by naming it"), |
768 | 764 | }, nil
|
769 | 765 | case *types.Map:
|
770 | 766 | // map[string][string] -> Record<string, string>
|
@@ -815,16 +811,11 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
|
815 | 811 | }
|
816 | 812 | genValue := ""
|
817 | 813 |
|
818 |
| - // Always wrap in parentheses for proper scoped types. |
819 |
| - // Running prettier on this output will remove redundant parenthesis, |
820 |
| - // so this makes our decision-making easier. |
821 |
| - // The example that breaks without this is: |
822 |
| - // readonly readonly string[][] |
823 | 814 | if underlying.GenericValue != "" {
|
824 |
| - genValue = "(readonly " + underlying.GenericValue + "[])" |
| 815 | + genValue = "Readonly<Array<" + underlying.GenericValue + ">>" |
825 | 816 | }
|
826 | 817 | return TypescriptType{
|
827 |
| - ValueType: "(readonly " + underlying.ValueType + "[])", |
| 818 | + ValueType: "Readonly<Array<" + underlying.ValueType + ">>", |
828 | 819 | GenericValue: genValue,
|
829 | 820 | AboveTypeLine: underlying.AboveTypeLine,
|
830 | 821 | GenericTypes: underlying.GenericTypes,
|
@@ -969,11 +960,10 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
|
969 | 960 | // You can handle your type manually in the switch list above, otherwise "any" will be used.
|
970 | 961 | // An easy way to fix this is to pull your external type into `codersdk` package, then it will
|
971 | 962 | // be known by the generator.
|
972 |
| - return TypescriptType{ValueType: "any", AboveTypeLine: fmt.Sprintf("%s\n%s", |
973 |
| - indentedComment(fmt.Sprintf("Named type %q unknown, using \"any\"", n.String())), |
974 |
| - // Linter needs to be disabled here, or else it will complain about the "any" type. |
975 |
| - indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- External type"), |
976 |
| - )}, nil |
| 963 | + return TypescriptType{ |
| 964 | + ValueType: "unknown", |
| 965 | + AboveTypeLine: indentedComment(fmt.Sprintf("Named type %q unknown, using \"unknown\"", n.String())), |
| 966 | + }, nil |
977 | 967 | }
|
978 | 968 |
|
979 | 969 | // Defer to the underlying type.
|
@@ -1002,21 +992,16 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
|
1002 | 992 | // This field is 'interface{}'. We can't infer any type from 'interface{}'
|
1003 | 993 | // so just use "any" as the type.
|
1004 | 994 | return TypescriptType{
|
1005 |
| - ValueType: "any", |
1006 |
| - AboveTypeLine: fmt.Sprintf("%s\n%s", |
1007 |
| - indentedComment("Empty interface{} type, cannot resolve the type."), |
1008 |
| - // Linter needs to be disabled here, or else it will complain about the "any" type. |
1009 |
| - indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- interface{}"), |
1010 |
| - ), |
| 995 | + ValueType: "unknown", |
| 996 | + AboveTypeLine: indentedComment("Empty interface{} type, cannot resolve the type."), |
1011 | 997 | }, nil
|
1012 | 998 | }
|
1013 | 999 |
|
1014 | 1000 | // Interfaces are difficult to determine the JSON type, so just return
|
1015 |
| - // an 'any'. |
| 1001 | + // an 'unknown'. |
1016 | 1002 | return TypescriptType{
|
1017 |
| - ValueType: "any", |
1018 |
| - AboveTypeLine: indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- Golang interface, unable to resolve type."), |
1019 |
| - Optional: false, |
| 1003 | + ValueType: "unknown", |
| 1004 | + Optional: false, |
1020 | 1005 | }, nil
|
1021 | 1006 | case *types.TypeParam:
|
1022 | 1007 | _, ok := ty.Underlying().(*types.Interface)
|
|
0 commit comments