how to infer type of a protobuf decoded message?

95 Views Asked by At

I have this MessageType extracted from a .proto file:

export type MessageType = {

    template_id: number
}

The decode function shows:

enter image description here

Maybe the protobuf library expects to extend with the above Object Type

class Message<T extends object = object>

Doing so it results in not finding the type.

import protobuf from 'protobufjs'
...
const { template_id }:protobuf.Message<MessageType> = decode(payload)

enter image description here

Property 'template_id' does not exist on type 'Message'.ts(2339)

I tried fixing it by using unknown keyword, but this can't be the solution?

decode(payload) as unknown as MessageType
0

There are 0 best solutions below