Search code examples
typescriptnestjsgrpc

How to generate protos for both NestJs and Typescript using ts-proto?


I want to generate protos that can be used by both nestjs and typescript client. For now i am generating protos by setting nestjs option to true using the ts-proto plugin. But the issue is that the generated protos dont have client implementation. but when i set the clientImp option to true, it doesn't generated client implementation in protos unless i set the nestJS flag to false, but the generated protos are only compatible with node and not with nestjs. is there a possibility to somehow generate protos that can be used by both nestjs and typescript client.

I tried setting nestjs and clientImp flag to true but it didnt generate protos with client implementation. But when i set the nestjs flag to false and clientImp to true, it generates the protos with client implementation but without controller interface which is needed for nestjs


Solution

  • I think this is answered in the ts-proto repo issues:

    You could potentially resolve your issue with multi-file generation by using the fileSuffix option, allowing you to generate grpc-js files as normal and then nest files like file-name.nest.ts.

    https://github.com/stephenh/ts-proto/issues/560#issuecomment-1132201095