ts-protoc-gen
ts-protoc-gen copied to clipboard
Remove List appendage for repeated fields
The appendage of "List" to repeated fields causses issues, can this be changed / is there a way to stop it generating with the appendage for the following reason.
Example message
message DataAggregated {
repeated Data data = 1;
}
message Data {
string example = 1
}
Generated output
export namespace DataAggregated {
export type AsObject = {
dataList: Array<Data.AsObject>,
}
}
Expected output
export namespace DataAggregated {
export type AsObject = {
data: Array<Data.AsObject>,
}
}
The Issue No data returned over GRPC
// I cannot use a return interface here as dataList is not part of the underlying
// GRPC message so i must return 'data'
get() {
return {
dataList: ['string', 'string']
}
}
Data successfully returned over GRPC
// I cannot use a return interface here as data does not exist in the interface
get() {
return {
data: ['string', 'string']
}
}
Service interface
export interface ServiceInterface {
get(data: Empty, metadata: Metadata): Observable< DataAggregated.AsObject>;
}
Response on calling server
const res = get();
console.log(res.data) // TsErr: Property 'data' does not exist on type 'AsObject'.ts(2339)
console.log(res.dataList) // undefined
For a use case where you do not want to use instances of the generated classes, but instead just plain objects, the typings are rendered useless. any chance this can be changed or is there hacky way to resolve this?
+1
@Jaypov did you figure out a way around this? I am having same problem here.
This is a temporary solution for me.
(<any>res).data
Can't use repeated fields without hacks right now. I'm trying to use this library to interact with GRPC server and stuck on this issue. In my opinion this issue should be marked as important. Hope this will be fixed soon.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This is still an issue.
Can someone provide the full description of the toolchain that is being used in this scenario please? The reason for asking is that the List
suffix is correct for the basic usage of this plugin with https://github.com/protocolbuffers/protobuf/tree/master/js unless I've misunderstood an edge case.
So this is not something that is caused by this plugin. It is the limitation of the official protoc compiler itself. Since this plugin has to match that scheme, it adds a suffix after repeated fields.
I and a few other people have been maintaining this plugin which generates a typescript file directly instead of dealing with javascript and d.ts bindings.
See: https://github.com/thesayyn/protoc-gen-ts/issues/39 and https://github.com/thesayyn/protoc-gen-ts
I have the same issue.