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

Mapping enum types to enum values #16

Closed
rickyp-uber opened this issue Jun 8, 2018 · 4 comments
Closed

Mapping enum types to enum values #16

rickyp-uber opened this issue Jun 8, 2018 · 4 comments

Comments

@rickyp-uber
Copy link
Collaborator

When translating thrift enums like so:

enum EntityErrorType {
    UNKNOWN = 0,
    NOT_EXIST,
    EXISTED,
}

Thrift2Flow generates two objects

export type EntityErrorTypeTypeValues = 0 | 1 | 2;
export type EntityErrorTypeType = 'UNKNOWN' | 'NOT_EXIST' | 'EXISTED';

Is there a way in flow to map these back to one another through flow or through this tool? Would it make more sense for this tool to generate out a single object like so?

export type EntityErrorTypeType = {
   'UNKNOWN': 0,
   'NOT_EXIST': 1,
   'EXISTED': 2
};
@rickyp-uber
Copy link
Collaborator Author

#17 should resolve this when merged by creating an new type called EntityErrorTypeTypeMap

@koulmomo
Copy link
Contributor

koulmomo commented Jun 9, 2018

You probably want to export a const and not a type.

ie

export const EntityErrorEnum = {
  UNKNOWN: 0,
  NOT_EXIST: 1,
  EXISTED: 2
};

// usage
import {EntityErrorEnum, type EntityErrorType} from 'path/to/thrift/def.thrift';

function (error:  EntityErrorType) {
  if (error === EntityErrorEnum.UNKNOWN) {
    // do something
  } else {
    // do something else
  }
}

@rickyp-uber
Copy link
Collaborator Author

Yea I ran into that when attempting to use it. Should be fixed in the latest version of the pull request #17

@rickyp-uber
Copy link
Collaborator Author

Resolved in 0.3.0

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