ts-protoc-gen icon indicating copy to clipboard operation
ts-protoc-gen copied to clipboard

Remove List appendage for repeated fields

Open Jaypov opened this issue 4 years ago • 10 comments

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?

Jaypov avatar Apr 17 '20 12:04 Jaypov

+1

frperezr avatar May 05 '20 03:05 frperezr

@Jaypov did you figure out a way around this? I am having same problem here.

godolatunji avatar Jul 11 '20 05:07 godolatunji

This is a temporary solution for me.

(<any>res).data

ChaoLiou avatar Sep 04 '20 06:09 ChaoLiou

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.

JorgenPo avatar Sep 08 '20 16:09 JorgenPo

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.

stale[bot] avatar Dec 19 '20 08:12 stale[bot]

This is still an issue.

schnapster avatar Feb 22 '21 14:02 schnapster

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.

MarcusLongmuir avatar Mar 26 '21 17:03 MarcusLongmuir

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

thesayyn avatar Apr 19 '21 12:04 thesayyn

I have the same issue.

Mahdidzt avatar Feb 17 '22 08:02 Mahdidzt