stephenh / ts-proto

An idiomatic protobuf generator for TypeScript
Apache License 2.0
2.13k stars 345 forks source link

Need help ts error from generated ts type 'ValidateBasketRequest' only refers to a type, but is being used as a value here. #253

Closed jinchi2013 closed 3 years ago

jinchi2013 commented 3 years ago

I'm using cmd below to generate the ts interface, basically I'm using the only types case.

protoc --proto_path={search-path-of-my-protos}  --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./{path-to-save-locally} ./{path-to-my-service-proto} --ts_proto_opt=outputEncodeMethods=false,outputJsonMethods=false,outputClientImpl-false,esModuleInterop=true,snakeToCamel=false,stringEnums=true,esModuleInterop=true

It works well for 99.9% of the cases, except service like below. UnifiedGateway is a service proto.

export interface UnifiedGateway {
  ValidateBasket(
    request: ValidateBasketRequest
  ): Promise<ValidateBasketResponse>;
}
export class UnifiedGatewayClientImpl implements UnifiedGateway {
  private readonly rpc: Rpc;
  constructor(rpc: Rpc) {
    this.rpc = rpc;
  }

  ValidateBasket(
    request: ValidateBasketRequest
  ): Promise<ValidateBasketResponse> {
    const data = ValidateBasketRequest.encode(request).finish();
    const promise = this.rpc.request(
      "com.priceline.usp.services.external.UnifiedGateway",
      "ValidateBasket",
      data
    );
    return promise.then((data) =>
      ValidateBasketResponse.decode(new _m0.Reader(data))
    );
  }
}

And I got typescript error around ValidateBasketResponse saying

'ValidateBasketRequest' only refers to a type, but is being used as a value here.

Any idea how can I resolve this error?

Thanks a lot.

stephenh commented 3 years ago

,outputClientImpl-false,

Looks like you have a - instead of an = in turning off the client output. :-)