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

Remove List appendage for repeated fields #225

Open
Jaypov opened this issue Apr 17, 2020 · 9 comments
Open

Remove List appendage for repeated fields #225

Jaypov opened this issue Apr 17, 2020 · 9 comments

Comments

@Jaypov
Copy link

Jaypov commented Apr 17, 2020

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?

@frperezr
Copy link

frperezr commented May 5, 2020

+1

@godolatunji
Copy link

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

@ChaoLiou
Copy link

ChaoLiou commented Sep 4, 2020

This is a temporary solution for me.

(<any>res).data

@JorgenPo
Copy link

JorgenPo commented Sep 8, 2020

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.

@stale
Copy link

stale bot commented Dec 19, 2020

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 stale bot added the wontfix label Dec 19, 2020
@schnapster
Copy link

This is still an issue.

@stale stale bot removed the wontfix label Feb 22, 2021
@MarcusLongmuir
Copy link
Contributor

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.

@thesayyn
Copy link

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: thesayyn/protoc-gen-ts#39 and https://github.com/thesayyn/protoc-gen-ts

@Mahdidzt
Copy link

I have the same issue.

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

9 participants