Skip to content

Commit e02d010

Browse files
henriiikstanley-cheung
authored andcommitted
update generated typescript files to work in strict mode
1 parent 3956048 commit e02d010

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

javascript/net/grpc/web/grpc_generator.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,11 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file,
369369
printer->Print(
370370
"client_: grpcWeb.AbstractClientBase;\n"
371371
"hostname_: string;\n"
372-
"credentials_: {};\n"
373-
"options_: { [s: string]: {}; };\n\n"
372+
"credentials_: null | { [index: string]: string; };\n"
373+
"options_: null | { [index: string]: string; };\n\n"
374374
"constructor (hostname: string,\n"
375-
" credentials: {},\n"
376-
" options: { [s: string]: {}; }) {\n");
375+
" credentials: null | { [index: string]: string; },\n"
376+
" options: null | { [index: string]: string; }) {\n");
377377
printer->Indent();
378378
printer->Print("if (!options) options = {};\n");
379379
if (vars["mode"] == GetModeVar(Mode::GRPCWEB)) {
@@ -466,8 +466,8 @@ void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) {
466466
printer->Indent();
467467
printer->Print(
468468
"constructor (hostname: string,\n"
469-
" credentials: {},\n"
470-
" options: { [s: string]: {}; });\n\n");
469+
" credentials: null | { [index: string]: string; },\n"
470+
" options: null | { [index: string]: string; });\n\n");
471471
for (int method_index = 0; method_index < service->method_count();
472472
++method_index) {
473473
const MethodDescriptor* method = service->method(method_index);
@@ -482,7 +482,8 @@ void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) {
482482
"request: $input_type$,\n"
483483
"metadata: grpcWeb.Metadata\n");
484484
printer->Outdent();
485-
printer->Print("): grpcWeb.ClientReadableStream;\n\n");
485+
printer->Print(vars,
486+
"): grpcWeb.ClientReadableStream<$output_type$>;\n\n");
486487
} else {
487488
printer->Print(vars, "$js_method_name$(\n");
488489
printer->Indent();
@@ -492,7 +493,8 @@ void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) {
492493
"callback: (err: grpcWeb.Error,\n"
493494
" response: $output_type$) => void\n");
494495
printer->Outdent();
495-
printer->Print("): grpcWeb.ClientReadableStream;\n\n");
496+
printer->Print(vars,
497+
"): grpcWeb.ClientReadableStream<$output_type$>;\n\n");
496498
}
497499
}
498500
}

net/grpc/gateway/examples/echo/ts-example/client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ class EchoApp {
101101
request.setMessageCount(count);
102102
request.setMessageInterval(EchoApp.INTERVAL);
103103

104-
const stream: grpcWeb.ClientReadableStream =
105-
this.echoService_.serverStreamingEcho(
106-
request, {'custom-header-1': 'value1'});
104+
const stream = this.echoService_.serverStreamingEcho(
105+
request, {'custom-header-1': 'value1'});
107106
const self = this;
108107
stream.on('data', (response: ServerStreamingEchoResponse) => {
109108
EchoApp.addRightMessage(response.getMessage());

net/grpc/gateway/examples/echo/ts-example/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"target": "es6",
44
"module": "commonjs",
5-
"noImplicitAny": true,
5+
"strict": true,
66
"allowJs": true,
77
"outDir": "./dist",
88
"types": ["node"],

packages/grpc-web/index.d.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,37 @@ declare module "grpc-web" {
33
export interface Metadata { [s: string]: string; }
44

55
export namespace AbstractClientBase {
6-
class MethodInfo {
7-
constructor (responseType: {},
8-
requestSerializeFn: (request: {}) => {},
9-
responseDeserializeFn: (bytes: {}) => {});
6+
class MethodInfo<Request, Response> {
7+
constructor (responseType: new () => Response,
8+
requestSerializeFn: (request: Request) => {},
9+
responseDeserializeFn: (bytes: {}) => Response);
1010
}
1111
}
1212

1313
export class AbstractClientBase {
14-
rpcCall (method: string,
15-
request: {},
14+
rpcCall<Request, Response> (method: string,
15+
request: Request,
1616
metadata: Metadata,
17-
methodInfo: AbstractClientBase.MethodInfo,
18-
callback: (err: Error, response: {}) => void
19-
): ClientReadableStream;
17+
methodInfo: AbstractClientBase.MethodInfo<Request, Response>,
18+
callback: (err: Error, response: Response) => void
19+
): ClientReadableStream<Response>;
2020

2121
serverStreaming (method: string,
22-
request: {},
22+
request: Request,
2323
metadata: Metadata,
24-
methodInfo: AbstractClientBase.MethodInfo
25-
): ClientReadableStream;
24+
methodInfo: AbstractClientBase.MethodInfo<Request, Response>
25+
): ClientReadableStream<Response>;
2626
}
2727

28-
export class ClientReadableStream {
29-
on (type: string,
30-
callback: (...args: Array<{}>) => void): ClientReadableStream;
28+
export class ClientReadableStream<Response> {
29+
on (type: "error",
30+
callback: (err: Error) => void): ClientReadableStream<Response>;
31+
on (type: "status",
32+
callback: (status: Status) => void): ClientReadableStream<Response>;
33+
on (type: "data",
34+
callback: (response: Response) => void): ClientReadableStream<Response>;
35+
on (type: "end",
36+
callback: () => void): ClientReadableStream<Response>;
3137
cancel (): void;
3238
}
3339

0 commit comments

Comments
 (0)