Skip to content

TS definitions missing for Root.fromDescriptor and Root.toDescriptor #1499

@tatemz

Description

@tatemz

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;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions