3

I have a proto(3) message like so:

message DataAggregated {
   repeated Data data = 1;
}

message Data {
   string example = 1
}

When generated types for this proto definition the word 'List' is appended to repeated fields, why is this, is there a legit reason and is there a way to stop this appendage? this causes massive headaches.

export namespace DataAggregated {
    export type AsObject = {
        dataList: Array<Data.AsObject>,
    }
}

The Issue

Note: Im using AsObject over class instances for reasons to complex to explain here, and are out of scope for this question

This returns nothing 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']
     }
  }

This returns the data

  // I cannot use a return interface here as data does not exist in the interface
  get() {
     return {
       data: ['string', 'string']
     }
  }

When calling the function from another server

 export interface ServiceInterface {
     get(data: Empty, metadata: Metadata): Observable< DataAggregated.AsObject>;
 }

 ....

const res = get();
console.log(res.data)     // TsErr: Property 'data' does not exist on type 'AsObject'.ts(2339)
console.log(res.dataList) // undefined

This renders the typings for repeated fields useless if you do not opt to use the classes. why append list when GRPC expects data instead of dataList this seems like an anti pattern

Jay P
  • 596
  • 7
  • 23

0 Answers0