mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 23:21:58 +08:00
[v2] Update experimental TS generation for bindings
This commit is contained in:
parent
485f5831ac
commit
06fa6850a1
@ -164,15 +164,15 @@ func (b *Bindings) GenerateBackendTS(targetfile string) error {
|
|||||||
var args slicer.StringSlicer
|
var args slicer.StringSlicer
|
||||||
for count, input := range methodDetails.Inputs {
|
for count, input := range methodDetails.Inputs {
|
||||||
arg := fmt.Sprintf("arg%d", count+1)
|
arg := fmt.Sprintf("arg%d", count+1)
|
||||||
args.Add(arg + ":" + goTypeToJSDocType(input.TypeName))
|
args.Add(arg + ":" + goTypeToTypescriptType(input.TypeName))
|
||||||
}
|
}
|
||||||
output.WriteString(args.Join(",") + "):")
|
output.WriteString(args.Join(",") + "):")
|
||||||
returnType := "Promise"
|
returnType := "Promise"
|
||||||
if methodDetails.OutputCount() > 0 {
|
if methodDetails.OutputCount() > 0 {
|
||||||
firstType := goTypeToJSDocType(methodDetails.Outputs[0].TypeName)
|
firstType := goTypeToTypescriptType(methodDetails.Outputs[0].TypeName)
|
||||||
returnType += "<" + firstType
|
returnType += "<" + firstType
|
||||||
if methodDetails.OutputCount() == 2 {
|
if methodDetails.OutputCount() == 2 {
|
||||||
secondType := goTypeToJSDocType(methodDetails.Outputs[1].TypeName)
|
secondType := goTypeToTypescriptType(methodDetails.Outputs[1].TypeName)
|
||||||
returnType += "|" + secondType
|
returnType += "|" + secondType
|
||||||
}
|
}
|
||||||
returnType += ">"
|
returnType += ">"
|
||||||
@ -216,7 +216,7 @@ func goTypeToJSDocType(input string) string {
|
|||||||
return "string"
|
return "string"
|
||||||
case strings.HasPrefix(input, "[]"):
|
case strings.HasPrefix(input, "[]"):
|
||||||
arrayType := goTypeToJSDocType(input[2:])
|
arrayType := goTypeToJSDocType(input[2:])
|
||||||
return "Array.<" + arrayType + ">"
|
return "Array<" + arrayType + ">"
|
||||||
default:
|
default:
|
||||||
if strings.ContainsRune(input, '.') {
|
if strings.ContainsRune(input, '.') {
|
||||||
return strings.Split(input, ".")[1]
|
return strings.Split(input, ".")[1]
|
||||||
@ -224,3 +224,11 @@ func goTypeToJSDocType(input string) string {
|
|||||||
return "any"
|
return "any"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func goTypeToTypescriptType(input string) string {
|
||||||
|
if strings.HasPrefix(input, "[]") {
|
||||||
|
arrayType := goTypeToJSDocType(input[2:])
|
||||||
|
return "Array<" + arrayType + ">"
|
||||||
|
}
|
||||||
|
return goTypeToJSDocType(input)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user