Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update typescript generation to work in strict mode #345

Merged
merged 1 commit into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions javascript/net/grpc/web/grpc_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,11 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file,
printer->Print(
"client_: grpcWeb.AbstractClientBase;\n"
"hostname_: string;\n"
"credentials_: {};\n"
"options_: { [s: string]: {}; };\n\n"
"credentials_: null | { [index: string]: string; };\n"
"options_: null | { [index: string]: string; };\n\n"
"constructor (hostname: string,\n"
" credentials: {},\n"
" options: { [s: string]: {}; }) {\n");
" credentials: null | { [index: string]: string; },\n"
" options: null | { [index: string]: string; }) {\n");
printer->Indent();
printer->Print("if (!options) options = {};\n");
if (vars["mode"] == GetModeVar(Mode::GRPCWEB)) {
Expand Down Expand Up @@ -466,8 +466,8 @@ void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) {
printer->Indent();
printer->Print(
"constructor (hostname: string,\n"
" credentials: {},\n"
" options: { [s: string]: {}; });\n\n");
" credentials: null | { [index: string]: string; },\n"
" options: null | { [index: string]: string; });\n\n");
for (int method_index = 0; method_index < service->method_count();
++method_index) {
const MethodDescriptor* method = service->method(method_index);
Expand All @@ -482,7 +482,8 @@ void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) {
"request: $input_type$,\n"
"metadata: grpcWeb.Metadata\n");
printer->Outdent();
printer->Print("): grpcWeb.ClientReadableStream;\n\n");
printer->Print(vars,
"): grpcWeb.ClientReadableStream<$output_type$>;\n\n");
} else {
printer->Print(vars, "$js_method_name$(\n");
printer->Indent();
Expand All @@ -492,7 +493,8 @@ void PrintGrpcWebDtsFile(Printer* printer, const FileDescriptor* file) {
"callback: (err: grpcWeb.Error,\n"
" response: $output_type$) => void\n");
printer->Outdent();
printer->Print("): grpcWeb.ClientReadableStream;\n\n");
printer->Print(vars,
"): grpcWeb.ClientReadableStream<$output_type$>;\n\n");
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions net/grpc/gateway/examples/echo/ts-example/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ class EchoApp {
request.setMessageCount(count);
request.setMessageInterval(EchoApp.INTERVAL);

const stream: grpcWeb.ClientReadableStream =
this.echoService_.serverStreamingEcho(
request, {'custom-header-1': 'value1'});
const stream = this.echoService_.serverStreamingEcho(
request, {'custom-header-1': 'value1'});
const self = this;
stream.on('data', (response: ServerStreamingEchoResponse) => {
EchoApp.addRightMessage(response.getMessage());
Expand Down
2 changes: 1 addition & 1 deletion net/grpc/gateway/examples/echo/ts-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"noImplicitAny": true,
"strict": true,
"allowJs": true,
"outDir": "./dist",
"types": ["node"],
Expand Down
36 changes: 21 additions & 15 deletions packages/grpc-web/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,37 @@ declare module "grpc-web" {
export interface Metadata { [s: string]: string; }

export namespace AbstractClientBase {
class MethodInfo {
constructor (responseType: {},
requestSerializeFn: (request: {}) => {},
responseDeserializeFn: (bytes: {}) => {});
class MethodInfo<Request, Response> {
constructor (responseType: new () => Response,
requestSerializeFn: (request: Request) => {},
responseDeserializeFn: (bytes: {}) => Response);
}
}

export class AbstractClientBase {
rpcCall (method: string,
request: {},
rpcCall<Request, Response> (method: string,
request: Request,
metadata: Metadata,
methodInfo: AbstractClientBase.MethodInfo,
callback: (err: Error, response: {}) => void
): ClientReadableStream;
methodInfo: AbstractClientBase.MethodInfo<Request, Response>,
callback: (err: Error, response: Response) => void
): ClientReadableStream<Response>;

serverStreaming (method: string,
request: {},
request: Request,
metadata: Metadata,
methodInfo: AbstractClientBase.MethodInfo
): ClientReadableStream;
methodInfo: AbstractClientBase.MethodInfo<Request, Response>
): ClientReadableStream<Response>;
}

export class ClientReadableStream {
on (type: string,
callback: (...args: Array<{}>) => void): ClientReadableStream;
export class ClientReadableStream<Response> {
on (type: "error",
callback: (err: Error) => void): ClientReadableStream<Response>;
on (type: "status",
callback: (status: Status) => void): ClientReadableStream<Response>;
on (type: "data",
callback: (response: Response) => void): ClientReadableStream<Response>;
on (type: "end",
callback: () => void): ClientReadableStream<Response>;
cancel (): void;
}

Expand Down