stephenh / ts-proto

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

How to use it? #279

Closed DenisVASI9 closed 3 years ago

DenisVASI9 commented 3 years ago

Hello, I'm a complete beginner, could you please tell me how to use this?

I created the database_pb.ts file with this command: protoc --plugin=node_modules/ts-proto/protoc-gen-ts_proto ./src/database/database.proto --ts_out="./generated/" --ts_proto_opt="addGrpcMetadata=true,nestJs=true"

What should I do next with this file? I also found various useful methods inside the file, like hasData and the like. But when I try to call them, the interpreter says that they don't exist. Please, can you tell me how to use them?

I use nest js

daniel-vera-g commented 3 years ago

Have you read through the following docs?:

  1. https://docs.nestjs.com/microservices/grpc
  2. https://github.com/stephenh/ts-proto#usage and then https://github.com/stephenh/ts-proto/blob/main/NESTJS.markdown
DenisVASI9 commented 3 years ago

No, I'm Russian :D

I really don't understand.

async findDevice(computer) { return await this.database.findDevice(computer).toPromise(); }

const res = await findDevice(device);

res.hasData()

this returns "res.hasData is not a function";

but .d.ts has:

hasData(): boolean; clearData(): void; getData(): Device | undefined; setData(value?: Device): void;

stephenh commented 3 years ago

Hey @DenisVASI9, yeah this doesn't sound like a bug but a project setup. Happy to accept fixes/translations/contributions of the docs, but sorry github issues aren't the best place for this sort of help.

If you want to make a public github repository with your current status, then others might be able to take a look / see where you're stuck, but as-is this is a pretty vague "something doesn't work" and it's really hard to know/guess what that is.