protobuf.js icon indicating copy to clipboard operation
protobuf.js copied to clipboard

TS definitions missing for Root.fromDescriptor and Root.toDescriptor

Open tatemz opened this issue 4 years ago • 1 comments

protobuf.js version: 6.10.1

After importing protobufjs/ext/descriptor, I should be able to call the fromDescriptor and toDescriptor methods without Typescript complaining

import { Message, Root } from 'protobufjs';
import * as descriptor from "protobufjs/ext/descriptor";

const root = new Root();
root.fromDescriptor({} as Message<descriptor.IFileDescriptorSet>);
Property 'fromDescriptor' does not exist on type 'typeof Root'.ts

Workaround (inspired by proto-loader):

declare module 'protobufjs' {
    interface Root {
        toDescriptor(protoVersion: string): Protobuf.Message<descriptor.IFileDescriptorSet> & descriptor.IFileDescriptorSet;
        fromDescriptor(descriptor: IFileDescriptorSet | $protobuf.Reader | Uint8Array): Root;
    }
}

tatemz avatar Oct 15 '20 04:10 tatemz

just got into the same issue working on creating a test case for #1784

ThePlenkov avatar Aug 18 '22 09:08 ThePlenkov