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

Type declaration for comment on IMethod is not optional #1842

Open
JE-FH opened this issue Dec 23, 2022 · 0 comments
Open

Type declaration for comment on IMethod is not optional #1842

JE-FH opened this issue Dec 23, 2022 · 0 comments

Comments

@JE-FH
Copy link

JE-FH commented Dec 23, 2022

protobuf.js version: 7.1.2

Typings for IMethod defines a field comment to be string, but comment is understandably undefined when there is no comment. I think this is supposed to be nullable as all other interfaces define the field comment as.

As far as i can tell, the following line 677 should be comment: (string|null) as all other comment fields are. Or even better, comment?: string.

I could create a pull request if this is correct :)

protobuf.js/index.d.ts

Lines 656 to 681 in d026849

export interface IMethod {
/** Method type */
type?: string;
/** Request type */
requestType: string;
/** Response type */
responseType: string;
/** Whether requests are streamed */
requestStream?: boolean;
/** Whether responses are streamed */
responseStream?: boolean;
/** Method options */
options?: { [k: string]: any };
/** Method comments */
comment: string;
/** Method options properly parsed into an object */
parsedOptions?: { [k: string]: any };
}

The missing comment field is displayed in this sample

//example.proto
syntax = "proto3";

package sample;

message SimpleRequest {
	string foo = 1;
}

message SimpleResponse {
	string bar = 1;
}

service SimpleService {
	rpc method1(SimpleRequest) returns (SimpleResponse);
}
const protobuf = require("protobufjs");

protobuf.load("sample.proto")
    .then((definition) => {
        const jsonDefinition = definition.toJSON();
        console.log(jsonDefinition.nested.sample.nested.SimpleService.methods.method1);
        //Will output { requestType: 'SimpleRequest', responseType: 'SimpleResponse' } 
        //which contradicts the type definition
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant