-
If I write a class like so:
And then attempt to make something that uses it like so:
I get this message:
Is there a more correct class to extend from in this scenario? I can resolve by changing the generic definition to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
This rolls into a related issue, which is that, as far as I can tell, I cannot convert an arbitrary message type to binary since there is no way to access the MessageType class's static methods without the generic type, which is hidden inside the generated message files. The following code doesn't work:
Is there a reasonable way to do this with any message type? |
Beta Was this translation helpful? Give feedback.
-
For the following proto: message Person {
string name = 1;
} We generate an interface: interface Person {
name: string;
} And an object, also named If you are familiar with gRPC-web, the interface is equivalent to what you get from For your StreamManager, you could do something like this: export class StreamManager<I extends object, O extends object> {
constructor(private readonly inputType: IMessageType<I>, private readonly outputType: IMessageType<O>) {...}
manage(input: I): O;
}
let pm = new StreamManager(Person, Person);
let p = pm.manage({name: "max"}) |
Beta Was this translation helpful? Give feedback.
For the following proto:
We generate an interface:
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: