Skip to content

Unclear from docs how to create generic functions using MessageType #180

Answered by timostamm
caesuric asked this question in Q&A
Discussion options

You must be logged in to vote

For the following proto:

message Person {
  string name = 1;
}

We generate an interface:

interface Person {
   name: string;
}

And an object, also named Person, that provides functions to create / decode / encode objects conforming to this interface.

If you are familiar with gRPC-web, the interface is equivalent to what you get from toObject() on a gRPC-web message. It is a plain object without methods. This has some advantages, but also the disadvantage that you have to pass the tuple of an object and it's MessageType around if you want to work on it generically.

For your StreamManager, you could do something like this:

export class StreamManager<I extends object, O extends object> { 
  c…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@caesuric
Comment options

Answer selected by caesuric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants