5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-11 14:39:30 +08:00

Typescript improvements

This commit is contained in:
Lea Anthony 2020-10-30 15:23:26 +11:00
parent 662b14fffb
commit 765ae8cd2b
3 changed files with 38 additions and 13 deletions

View File

@ -12,6 +12,6 @@
* @returns {Promise} * @returns {Promise}
*/ */
export function {{.Name}}({{.InputsAsJSText}}) { export function {{.Name}}({{.InputsAsJSText}}) {
return window.backend.{{$.Name}}.{{.Name}}(); return window.backend.{{$.Name}}.{{.Name}}({{.InputsAsJSText}});
} }
{{end}} {{end}}

View File

@ -75,6 +75,25 @@ func parsePackages() ([]*Package, error) {
}, },
}, },
}, },
{
Name: "TwoInputsAndOutput",
Inputs: []*Parameter{
{
Name: "name",
Type: reflect.String,
},
{
Name: "age",
Type: reflect.Uint8,
},
},
Outputs: []*Parameter{
{
Name: "result",
Type: reflect.Bool,
},
},
},
}, },
}) })

View File

@ -8,8 +8,9 @@ import (
// Parameter defines a parameter used by a struct method // Parameter defines a parameter used by a struct method
type Parameter struct { type Parameter struct {
Name string Name string
Type reflect.Kind Type reflect.Kind
StructName string
} }
// JSType returns the Javascript equivalent of the // JSType returns the Javascript equivalent of the
@ -55,19 +56,24 @@ func (m *Method) InputsAsTSText() string {
// formatted in a way acceptable to Javascript // formatted in a way acceptable to Javascript
func (m *Method) OutputsAsTSText() string { func (m *Method) OutputsAsTSText() string {
if len(m.Outputs) != 2 { if len(m.Outputs) == 0 {
return "any" return "void"
} }
jsType := goTypeToJS(m.Outputs[1].Type) var result []string
switch jsType {
case JsArray: for _, output := range m.Outputs {
return "Array<any>" jsType := goTypeToJS(output.Type)
case JsObject: switch jsType {
return "any" case JsArray:
default: result = append(result, "Array<any>")
return string(jsType) case JsObject:
result = append(result, "any")
default:
result = append(result, string(jsType))
}
} }
return strings.Join(result, ", ")
} }
// func generateStructFile() { // func generateStructFile() {