Protobuf.js: enum missing when generate to d.ts without field 'package'

Created on 26 Jul 2019  ·  4Comments  ·  Source: protobufjs/protobuf.js

protobuf.js version: 6.8.8

// file: test.proto without filed 'package' 
syntax = "proto3";
enum OuterEnum {
  FOO = 1;
  BAR = 2;
}

```bash
// run commond
./node_modules/.bin/pbjs -t static-module -w commonjs -o compiled.js test.proto
./node_modules/.bin/pbts -o compiled.d.ts compiled.js

**Expect Result for file: compiled.d.ts**
```typescript
enum OuterEnum {
        FOO = 1,
        BAR = 2
 }

Real Result for file: compiled.d.ts ❌❌

import * as $protobuf from "protobufjs";

Then I Change proto file and run commond again:

// file: test.proto with filed 'package' 
syntax = "proto3";

package test; // add 

enum OuterEnum {
  FOO = 1;
  BAR = 2;
}

Real Result for file: compiled.d.ts ✅✅

import * as $protobuf from "protobufjs";
/** Namespace test. */
export namespace test {

    /** OuterEnum enum. */
    enum OuterEnum {
        FOO = 1,
        BAR = 2
    }
}

Is it necessary to add field 'package' for enum ?

Most helpful comment

+1

All 4 comments

I face with the same problem.
When I don't write 'package' in a proto file, the generated d.ts file has some grammatical errors (e.g. a class is extended from a certain interface, but the interface isn't declared) in addition to lack of enum.

+1

I think I ran into this issue recently as well and tracked it down to an issue handling enums in jsdoc. I just created a pull request to fix the issue, but it may be awhile before it's merged in (assuming it's accepted): https://github.com/jsdoc/jsdoc/pull/1686

[email protected] will cause the enum problem, so I solved it by:

cd node_modules/protobufjs
sed -i "s/\"jsdoc\": \".*\"/\"jsdoc\": \"3.5.5\"/" package.json
cd cli
npm install [email protected]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

filipednb picture filipednb  ·  5Comments

psaelango picture psaelango  ·  4Comments

taylorcode picture taylorcode  ·  4Comments

chloe2018s picture chloe2018s  ·  3Comments

andiwonder picture andiwonder  ·  3Comments