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

protoc-gen-tstypes: Nested enums duplication identifier & namespace issue #20

Closed
mousavian opened this issue Aug 2, 2018 · 2 comments
Closed

Comments

@mousavian
Copy link

Hi Travis,
Assume we have a message definition like this:

syntax = "proto3";

package nested;

message Notification {
  enum Type {
    UNSPECIFIED = 0;
    TEXT = 1;
    VIDEO = 2;
    AUDIO = 3;
  }

  Type message_type = 1;
  string content = 2;
}

message Tweet {
  enum Type {
    UNSPECIFIED = 0;
    ORIGINAL = 1;
    RETWEET = 2;
  }

  Type tweet_type = 1;
  string content = 2;
}

When we compile, there will be two Enums under same namespace and tsc check throws this error:

TS2300: Duplicate identifier 'UNSPECIFIED'.
UNSPECIFIED = "UNSPECIFIED",
~~~~~~~~~~~

Output:

declare namespace nested {
    export enum Type {
        UNSPECIFIED = "UNSPECIFIED",
        TEXT = "TEXT",
        VIDEO = "VIDEO",
        AUDIO = "AUDIO",
    }
    export interface Notification {
        messageType?: Type;
        content?: string;
    }
    export enum Type {
        UNSPECIFIED = "UNSPECIFIED",
        ORIGINAL = "ORIGINAL",
        RETWEET = "RETWEET",
    }
    export interface Tweet {
        tweetType?: Type;
        content?: string;
    }
}

Do you any idea how this can get resolved without renaming enum names?

@Akiq2016
Copy link
Contributor

Akiq2016 commented Sep 4, 2018

input

syntax = "proto3";

package nested;

message Notification {
  enum Type {
    UNSPECIFIED = 0;
    TEXT = 1;
    VIDEO = 2;
    AUDIO = 3;
  }

  Type message_type = 1;
  string content = 2;
}

message Tweet {
  enum Type {
    UNSPECIFIED = 0;
    ORIGINAL = 1;
    RETWEET = 2;
  }

  Type tweet_type = 1;
  string content = 2;
}

the expected output should be like this ?

declare namespace nested {
    export enum Notification_Type {
        UNSPECIFIED = "UNSPECIFIED",
        TEXT = "TEXT",
        VIDEO = "VIDEO",
        AUDIO = "AUDIO",
    }
    export interface Notification {
        messageType?: string;
        content?: string;
    }
    export enum Tweet_Type {
        UNSPECIFIED = "UNSPECIFIED",
        ORIGINAL = "ORIGINAL",
        RETWEET = "RETWEET",
    }
    export interface Tweet {
        tweetType?: string;
        content?: string;
    }
}

@tmc

@tmc
Copy link
Owner

tmc commented Sep 5, 2018

This is resolved by #24

@tmc tmc closed this as completed Sep 5, 2018
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

3 participants