mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
fix: use null and extend on types
This commit is contained in:
parent
f64c4e12e8
commit
1e249e4602
@ -34,11 +34,16 @@ func (v *Value) tsType(mappings config.TypeScriptMappings, scalars map[string]*S
|
||||
ts.app(",")
|
||||
v.Map.Value.tsType(mappings, scalars, structs, ts)
|
||||
ts.app(">")
|
||||
ts.app("|null")
|
||||
case v.Array != nil:
|
||||
if v.Array.Value.ScalarType != ScalarTypeByte {
|
||||
ts.app("Array<")
|
||||
}
|
||||
v.Array.Value.tsType(mappings, scalars, structs, ts)
|
||||
if v.Array.Value.ScalarType != ScalarTypeByte {
|
||||
ts.app("[]")
|
||||
ts.app(">")
|
||||
}
|
||||
ts.app("|null")
|
||||
case v.Scalar != nil:
|
||||
if v.Scalar.Package != "" {
|
||||
mapping, ok := mappings[v.Scalar.Package]
|
||||
@ -89,6 +94,9 @@ func (v *Value) tsType(mappings config.TypeScriptMappings, scalars map[string]*S
|
||||
}
|
||||
|
||||
ts.app(tsModule + "." + v.StructType.Name)
|
||||
if v.IsPtr {
|
||||
ts.app("|null")
|
||||
}
|
||||
return
|
||||
}
|
||||
ts.app(v.StructType.Name)
|
||||
@ -97,10 +105,19 @@ func (v *Value) tsType(mappings config.TypeScriptMappings, scalars map[string]*S
|
||||
ts.l("{").ind(1)
|
||||
renderStructFields(v.Struct.Fields, mappings, scalars, structs, ts)
|
||||
ts.ind(-1).app("}")
|
||||
if v.IsPtr {
|
||||
ts.app("|null")
|
||||
}
|
||||
case len(v.ScalarType) > 0:
|
||||
ts.app(tsTypeFromScalarType(v.ScalarType))
|
||||
if v.IsPtr {
|
||||
ts.app("|null")
|
||||
}
|
||||
default:
|
||||
ts.app("any")
|
||||
if v.IsPtr {
|
||||
ts.app("|null")
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -121,10 +138,7 @@ func renderStructFields(fields []*Field, mappings config.TypeScriptMappings, sca
|
||||
continue
|
||||
}
|
||||
ts.app(f.tsName())
|
||||
if f.Value.IsPtr ||
|
||||
f.Value.Map != nil ||
|
||||
f.Value.Array != nil ||
|
||||
(f.JSONInfo != nil && f.JSONInfo.OmitEmpty) {
|
||||
if f.JSONInfo != nil && f.JSONInfo.OmitEmpty {
|
||||
ts.app("?")
|
||||
}
|
||||
ts.app(":")
|
||||
|
||||
@ -48,14 +48,14 @@ func renderTypescriptClientAsync(service *Service, mappings config.TypeScriptMap
|
||||
ts.app(", ")
|
||||
}
|
||||
ts.app(arg.tsName())
|
||||
ts.app(":")
|
||||
arg.Value.tsType(mappings, scalars, structs, ts)
|
||||
if arg.Value.IsPtr ||
|
||||
arg.Value.Map != nil ||
|
||||
arg.Value.Array != nil ||
|
||||
(arg.JSONInfo != nil && arg.JSONInfo.OmitEmpty) {
|
||||
ts.app("?")
|
||||
ts.app("|null")
|
||||
}
|
||||
ts.app(":")
|
||||
arg.Value.tsType(mappings, scalars, structs, ts)
|
||||
callArgs = append(callArgs, arg.Name)
|
||||
argCount++
|
||||
}
|
||||
@ -97,11 +97,11 @@ func renderTypescriptClientAsync(service *Service, mappings config.TypeScriptMap
|
||||
}
|
||||
|
||||
innerReturnTypeTS.app(strconv.Itoa(index))
|
||||
if isNilable {
|
||||
innerReturnTypeTS.app("?")
|
||||
}
|
||||
innerReturnTypeTS.app(":")
|
||||
retField.Value.tsType(mappings, scalars, structs, innerReturnTypeTS)
|
||||
if isNilable {
|
||||
innerReturnTypeTS.app("|null")
|
||||
}
|
||||
|
||||
if index == len(method.Return)-1 && retField.Value.IsError {
|
||||
throwLastError = true
|
||||
@ -113,18 +113,18 @@ func renderTypescriptClientAsync(service *Service, mappings config.TypeScriptMap
|
||||
retField.Value.tsType(mappings, scalars, structs, firstReturnTypeTS)
|
||||
firstReturnType = firstReturnTypeTS.string()
|
||||
if isNilable {
|
||||
firstReturnType += "|undefined"
|
||||
firstReturnType += "|null"
|
||||
}
|
||||
//firstReturnFieldName = retArgName
|
||||
}
|
||||
countReturns++
|
||||
returnTypeTS.app(retArgName)
|
||||
if isNilable {
|
||||
returnTypeTS.app("?")
|
||||
}
|
||||
returnTypeTS.app(":")
|
||||
responseObject += responseObjectPrefix + retArgName + " : response[" + strconv.Itoa(index) + "]"
|
||||
retField.Value.tsType(mappings, scalars, structs, returnTypeTS)
|
||||
if isNilable {
|
||||
returnTypeTS.app("|null")
|
||||
}
|
||||
}
|
||||
responseObjectPrefix = ", "
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user