Skip to content

Commit 982bdcf

Browse files
committed
Use bool const type for rpc type
Uses const types for `requestStream` and `responseStream`, either `true` or `false` types instead of generic `boolean` TS types allowing advanced call type inference from the service definition. Higher abstraction framework libraries, such as https://github.com/malijs/mali could leverage advanced type inference to hint/check specific type handlers if this information would be part of the type rpc service type definition. At this point, the only way to determine thy type of RPC is using I{{{serviceName}}}Server interface, which must be linked manually to I{{{serviceName}}}Service methods. For registring handlers at runtime, only e.g. `GreeterService` and corresponding implementation is required, manually adding `IGreeterServer` is possible, but troublesome. This would not be required if rpc type could be inferred using the const booleans to define the type. This change does is not a breaking change and the const boolean types are working correctly since the oldest available version on TS playground 2.4.1. See playground link in the trailers. There are no obvoius disadvantages to using const booleans and change could potentially give node grpc frameworks more power for sophisticated type inference. See: https://www.typescriptlang.org/play/?ts=2.4.1#code/MYewdgzgLgBAhsYBTADlAKgJwK5JgXhgAoA3OAGwC4YockBKAgPhjPIChRJYFk0AxChDyFSFagDMhDZqwrt2vVBjpEp5YfUWJlgjUjXStStFlxFauYzoHSLdekA
1 parent ecc1ab8 commit 982bdcf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lib/template/svc_tsd.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ interface I{{{serviceName}}}Service extends grpc.ServiceDefinition<grpc.UntypedS
1818
{{#each methods}}
1919
interface I{{{serviceName}}}Service_I{{{methodName}}} extends grpc.MethodDefinition<{{{requestTypeName}}}, {{{responseTypeName}}}> {
2020
path: string; // "/{{{packageName}}}.{{{serviceName}}}/{{{methodName}}}"
21-
requestStream: boolean; // {{{requestStream}}}
22-
responseStream: boolean; // {{{responseStream}}}
21+
requestStream: {{{requestStream}}};
22+
responseStream: {{{responseStream}}};
2323
requestSerialize: grpc.serialize<{{{requestTypeName}}}>;
2424
requestDeserialize: grpc.deserialize<{{{requestTypeName}}}>;
2525
responseSerialize: grpc.serialize<{{{responseTypeName}}}>;

0 commit comments

Comments
 (0)