Skip to content

Commit 7f3a940

Browse files
committed
fix: map core types in succinct method return types
Succinct methods (eg. `Delete(Req) => (ok: bool)`) emitted raw RIDL type names like `bool` instead of mapped TypeScript types like `boolean`. The templates used `{{(index $method.Outputs 0).Type}}` which renders via Go's Stringer, bypassing the $typeMap. Fix: use `{{template "type" ...}}` (which resolves through $typeMap) for succinct output types in clientInterface, client, and serverInterface templates. Also handle the void case (no outputs) for succinct methods in clientInterface and serverInterface.
1 parent 51a7ad2 commit 7f3a940

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

client.go.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ export class {{$service.Name}} implements {{$service.Name}}Client {
4646
{{- $methodRespName := "" -}}
4747
{{- if $method.Succinct -}}
4848
{{- $methodReqName = (index $method.Inputs 0).Type -}}
49-
{{- $methodRespName = (index $method.Outputs 0).Type -}}
49+
{{- if gt (len $method.Outputs) 0 -}}
50+
{{- $methodRespName = (index $method.Outputs 0).Type -}}
51+
{{- if isCoreType (index $method.Outputs 0).Type -}}
52+
{{- $methodRespName = get $typeMap (index $method.Outputs 0).Type -}}
53+
{{- end -}}
54+
{{- end -}}
5055
{{- else -}}
5156
{{- if $opts.compat -}}
5257
{{- $methodReqName = printf "%sArgs" $method.Name -}}
@@ -56,7 +61,7 @@ export class {{$service.Name}} implements {{$service.Name}}Client {
5661
{{- $methodRespName = printf "%sResponse" $method.Name -}}
5762
{{- end -}}
5863
{{- end}}
59-
{{firstLetterToLower .Name}} = ({{template "methodInputs" dict "Method" . "Opts" $opts "TypeMap" $typeMap}}): {{if $method.StreamOutput}}WebrpcStreamController{{else}}{{if $method.Succinct}}Promise<{{(index $method.Outputs 0).Type}}>{{else}}Promise<{{$method.Name}}{{if $opts.compat}}Return{{else}}Response{{end}}>{{end}}{{end}} => {
64+
{{firstLetterToLower .Name}} = ({{template "methodInputs" dict "Method" . "Opts" $opts "TypeMap" $typeMap}}): {{if $method.StreamOutput}}WebrpcStreamController{{else}}{{if and $method.Succinct (gt (len $method.Outputs) 0)}}Promise<{{template "type" dict "Type" (index $method.Outputs 0).Type "TypeMap" $typeMap}}>{{else if $method.Succinct}}Promise<void>{{else}}Promise<{{$method.Name}}{{if $opts.compat}}Return{{else}}Response{{end}}>{{end}}{{end}} => {
6065
{{- if $method.StreamOutput }}
6166
const abortController = new AbortController()
6267
const abortSignal = abortController.signal

clientInterface.go.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface {{$service.Name}}Client {
2828
* @deprecated {{ $deprecated.Value }}
2929
*/
3030
{{- end }}
31-
{{firstLetterToLower $method.Name}}({{template "methodInputs" dict "Method" $method "TypeMap" $typeMap "Opts" $opts}}): {{if $method.StreamOutput}}WebrpcStreamController{{else}}{{if $method.Succinct}}Promise<{{(index $method.Outputs 0).Type}}>{{else}}Promise<{{$method.Name}}{{if $opts.compat}}Return{{else}}Response{{end}}>{{end}}{{end}}
31+
{{firstLetterToLower $method.Name}}({{template "methodInputs" dict "Method" $method "TypeMap" $typeMap "Opts" $opts}}): {{if $method.StreamOutput}}WebrpcStreamController{{else}}{{if and $method.Succinct (gt (len $method.Outputs) 0)}}Promise<{{template "type" dict "Type" (index $method.Outputs 0).Type "TypeMap" $typeMap}}>{{else if $method.Succinct}}Promise<void>{{else}}Promise<{{$method.Name}}{{if $opts.compat}}Return{{else}}Response{{end}}>{{end}}{{end}}
3232
{{- if lt (add $i 1) (len $service.Methods)}}{{"\n"}}{{end}}
3333
{{- end}}
3434
}

serverInterface.go.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
export interface {{$service.Name}}Server<Context = unknown> {
1414
{{- range $_, $method := $service.Methods}}
1515
{{- if $method.Succinct }}
16-
{{firstLetterToLower $method.Name}}(ctx: Context, req: {{(index $method.Inputs 0).Type}}): Promise<{{(index $method.Outputs 0).Type}}>
16+
{{firstLetterToLower $method.Name}}(ctx: Context, req: {{(index $method.Inputs 0).Type}}): Promise<{{if gt (len $method.Outputs) 0}}{{template "type" dict "Type" (index $method.Outputs 0).Type "TypeMap" $typeMap}}{{else}}void{{end}}>
1717
{{- else}}
1818
{{- if $opts.compat }}
1919
{{firstLetterToLower $method.Name}}(ctx: Context, req: {{$method.Name}}Args): Promise<{{$method.Name}}Return>

0 commit comments

Comments
 (0)