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

Handling of enums #157

Merged

Conversation

mattvagni
Copy link
Contributor

@mattvagni mattvagni commented Mar 30, 2019

More detail in: #156

Changes

  • This changes how the type generation handles protobuf enums
  • Regenerated all examples to run tests against

Verification

I checked and there seem to be a fair few tests for enum handling, the code changes are backwards compatible so they were not modified. Not sure if there are any additional tests worth writing? I did however have to change some of the casting in the integration test for maps - not sure if the changes makes sense though 🤔

Copy link
Contributor

@jonny-improbable jonny-improbable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Technically this is not a breaking change as anyone that was relying on the enum behavior would have problems at runtime :D

@jonny-improbable jonny-improbable merged commit 901b08e into improbable-eng:master Apr 3, 2019
@mattvagni
Copy link
Contributor Author

Haha brave 😅 Ok, thanks for merging this so quickly.

@jonny-improbable
Copy link
Contributor

Fortune favours the brave... plus we can rely on feedback from the community if anything goes proper bang :D

You can dogfood it yourself by upgrading to 0.9.1-pre.901b08e via npm.

@mahileeb
Copy link

mahileeb commented Oct 20, 2019

Hi,

this change is causing compile errors for our app where we use the enum as a field type, e.g. the mode field in the below

type OwnProps = {
    name?: string;
    mode?: EnvironmentMode;
    version?: string;
    build?: string;
    className?: string;
}

causes

(8,12): 'EnvironmentMode' refers to a value, but is being used as a type here.

If I use the generated EnvironmentModeMap interface then it will compile

@mattvagni
Copy link
Contributor Author

@mahileeb Could it be that you are importing EnvironmentMap object from the generated js client, not the typescript type?

Otherwise an example repo/gist would be helpful in order for me to help.

@mahileeb
Copy link

Hmm, the import looks like:

import { EnvironmentMode } from "protobuf/generated/com/mahifx/model/echo_protomap_pb";

Is that the correct way to import it? Here's gist of the proto schema and the usage: https://gist.github.com/mahileeb/1ce0c625634d10595351c1110711901f

@jacobfederer
Copy link

Any update on this issue? This is the dealbreaker for upgrading to 0.10 and higher.

@yoyomolinas
Copy link

yoyomolinas commented Mar 25, 2021

With #157 many of us are unable to use Protobuf enums with Typescript. As pointed out in #187 and #268, I think this issue needs further attention. Any clarification appreciated.

@thesayyn
Copy link

There is an alternative plugin that you can use to solve this.
See: thesayyn/protoc-gen-ts#39

@screenpunch
Copy link

We're also stuck with 0.9, this change has made protobuf enums unusable for us also.

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

Successfully merging this pull request may close these issues.

None yet

7 participants