Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums not working #32

Closed
NfNitLoop opened this issue Feb 18, 2021 · 2 comments
Closed

Enums not working #32

NfNitLoop opened this issue Feb 18, 2021 · 2 comments

Comments

@NfNitLoop
Copy link

The docs say that enums are supported, but they're not being generated in my use. I've created a minimal example here.

Steps to reproduce

package.json:

{
    "dependencies": {
        "google-protobuf": "^3.14.0",
        "protoc-gen-ts": "^0.3.4",
        "typescript": "^3"
    },
    "scripts": {
        "proto": "protoc --plugin=./node_modules/.bin/protoc-gen-ts.cmd --ts_out=. --proto_path=. sample.proto"
    }
}

sample.proto:

syntax = "proto3";

message Example {

    Foo foo = 1;
}

enum Foo {
    UNKNOWN = 0;

    BAR = 1;
    BAZ = 2;
}

Run:

npm install
npm run proto

Resulting output (does not contain an enum Foo):

import * as pb_1 from "google-protobuf";
export class Example extends pb_1.Message {
    constructor(data?: any[] | {
        foo?: Foo;
    }) {
        super();
        pb_1.Message.initialize(this, Array.isArray(data) && data, 0, -1, [], null);
        if (!Array.isArray(data) && typeof data == "object") {
            this.foo = data.foo;
        }
    }
    get foo(): Foo {
        return pb_1.Message.getFieldWithDefault(this, 1, undefined) as Foo;
    }
    set foo(value: Foo) {
        pb_1.Message.setField(this, 1, value);
    }
    toObject() {
        return {
            foo: this.foo
        };
    }
    serialize(w?: pb_1.BinaryWriter): Uint8Array | undefined {
        const writer = w || new pb_1.BinaryWriter();
        if (this.foo !== undefined)
            writer.writeEnum(1, this.foo);
        if (!w)
            return writer.getResultBuffer();
    }
    serializeBinary(): Uint8Array { throw new Error("Method not implemented."); }
    static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Example {
        const reader = bytes instanceof Uint8Array ? new pb_1.BinaryReader(bytes) : bytes, message = new Example();
        while (reader.nextField()) {
            if (reader.isEndGroup())
                break;
            switch (reader.getFieldNumber()) {
                case 1:
                    message.foo = reader.readEnum();
                    break;
                default: reader.skipField();
            }
        }
        return message;
    }
}
@thesayyn
Copy link
Owner

i can reproduce this. Fixed by c765e3c

@thesayyn
Copy link
Owner

thesayyn commented Apr 7, 2021

0.3.5 has landed and must have fixed this problem already.

Feel free to reopen it happens again.

@thesayyn thesayyn closed this as completed Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants