Protobuf.js: pbts doesn't generate enum typings when the enum is defined after its use

Created on 10 Jan 2020  路  5Comments  路  Source: protobufjs/protobuf.js

protobuf.js version: 6.8.8

Take the following .proto file:

syntax = "proto3";

message Test {
    Status status = 0;
}

enum Status {
    STATUS_ERROR = 0;
    STATUS_OK = 1;
}

With the following commands:

pbjs -t static-module -w es6 -o ./test.js ./test.proto
pbts -o ./test.d.ts ./test.js

The generated .d.ts file will be unusable, as it references the type Status, buts its definition is missing. Using commonjs instead of es6 yields the same results.

Reversing the order of the definitions leads to a different result: while a Status definition is emitted, now ITest is missing instead.

Most helpful comment

Moreover, it seems that messages defined after an enum declaration do not have appropriate interfaces. It's utterly broken and is preventing successful builds

All 5 comments

~The issue seems to be fixed in the protobuf.js master, when can we expect a new release?~

It seems the issue occurs depending on the versions of installed dependencies of the CLI:

  • When I clone the protobuf.js repo and run npm install in both the repository root and the cli subdir, correct definitions are emitted
  • When I leave out any of the npm install runs or use npm or yarn to install protobuf.js from the NPM registry or directly from the Git repo, pbjs/pbts will install additional dependencies on first run. Whenever this happens, the installation emits broken Typescript declarations.

Running into same issues

Moreover, it seems that messages defined after an enum declaration do not have appropriate interfaces. It's utterly broken and is preventing successful builds

@dcodeIO did https://github.com/protobufjs/protobuf.js/pull/1356 resolve this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RP-3 picture RP-3  路  4Comments

asafcombo picture asafcombo  路  4Comments

zD98 picture zD98  路  3Comments

b1naryMan picture b1naryMan  路  4Comments

chloe2018s picture chloe2018s  路  3Comments