improbable-eng / ts-protoc-gen

Protocol Buffers Compiler (protoc) plugin for TypeScript and gRPC-Web.
Apache License 2.0
1.37k stars 172 forks source link

Interfaces are created for proto enumerations #268

Closed Alex66955 closed 3 years ago

Alex66955 commented 3 years ago

ts-protoc-gen: 0.14.0 libprotoc: 3.15.6

What happened Updating module to the last version causes creation of interfaces instead of enumerations Proto:

enum scaleIdx {
    SCALE_DISPLAYED = 0;
    SCALE_1 = 1;
    SCALE_2 = 2;
    SCALE_COMPOUND = 3;
}

d.ts:

export interface scaleIdxMap {
  SCALE_DISPLAYED: 0;
  SCALE_1: 1;
  SCALE_2: 2;
  SCALE_COMPOUND: 3;
}

export const scaleIdx: scaleIdxMap;

What you expected to happen d.ts:

export enum scaleIdx {
  SCALE_DISPLAYED = 0,
  SCALE_1 = 1,
  SCALE_2 = 2,
  SCALE_COMPOUND = 3,
}

Full logs to relevant components Executed command: protoc --plugin=protoc-gen-ts=node_modules/.bin/protoc-gen-ts --ts_out=generated --proto_path=protos --proto_path=shared/protos protos/*.proto shared/protos/*.proto shared/protos/generated/*.proto

thesayyn commented 3 years ago

I would recommend a plugin that we have been developing and maintaining for these edge cases which is caused by protocol buffers javascript output itself.

https://github.com/thesayyn/protoc-gen-ts

AJLoveChina commented 3 years ago

I am facing the same issue. I really need protoc enum to be compiled as enum, not interface..

thesayyn commented 3 years ago

@AJLoveChina you can check out the alternative.

Alex66955 commented 3 years ago

I also solved my issue with that plugin.