improbable-eng / ts-protoc-gen

Protocol Buffers Compiler (protoc) plugin for TypeScript and gRPC-Web.
Apache License 2.0
1.37k stars 172 forks source link

setXX() method return type is wrong in .d.ts file #285

Closed DRL9 closed 3 years ago

DRL9 commented 3 years ago

Versions of relevant software used google-protobuf: 3.17.3 ts-protoc-gen: 0.15.0

What happened .d.ts file setXX() and addXXs() return type are wrong

What you expected to happen That method should return this replace void

How to reproduce it (as minimally and precisely as possible):

syntax = "proto3";

package pd;

message Test {
  string a_string = 1;
  repeated string a_array = 2;
}

output js code segment

/**
 * @param {string} value
 * @return {!proto.pd.Test} returns this
 */
proto.pd.Test.prototype.setAString = function(value) {
  return jspb.Message.setProto3StringField(this, 1, value);
};

/**
 * @param {!Array<string>} value
 * @return {!proto.pd.Test} returns this
 */
proto.pd.Test.prototype.setAArrayList = function(value) {
  return jspb.Message.setField(this, 2, value || []);
};

/**
 * @param {string} value
 * @param {number=} opt_index
 * @return {!proto.pd.Test} returns this
 */
proto.pd.Test.prototype.addAArray = function(value, opt_index) {
  return jspb.Message.addToRepeatedField(this, 2, value, opt_index);
};

output .d.ts segment

setAString(value: string): void;

setAArrayList(value: Array<string>): void;
addAArray(value: string, index?: number): string;

google-protobuf marked the return type of these method as this. However, output'ssetX() return void, and addXX() return the inputValue's type.

I expect to generate the following code:

setAString(value: string): this;

setAArrayList(value: Array<string>): this;
addAArray(value: string, index?: number): this;
DRL9 commented 3 years ago

duplicated #218