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

String enums have reverse mapping #16761

Closed
StrahilKazlachev opened this issue Jun 27, 2017 · 6 comments
Closed

String enums have reverse mapping #16761

StrahilKazlachev opened this issue Jun 27, 2017 · 6 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@StrahilKazlachev
Copy link

StrahilKazlachev commented Jun 27, 2017

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.20170627)

In the PR for string enums it is said they do not have reverse mapping. When I compile the following I get a different output from the shown in the PR. Is this a change?

Code

enum ActionType {
    AddUser = "ADD_USER",
    DeleteUser = "DELETE_USER",
    RenameUser = "RENAME_USER"
}

enum Mixed {
    A,
    B,
    C = "hi",
    D = 10,
    E,
    F = "bye"
}

Expected behavior:

var ActionType;
(function (ActionType) {
    ActionType["AddUser"] = "ADD_USER";
    ActionType["DeleteUser"] = "DELETE_USER";
    ActionType["RenameUser"] = "RENAME_USER";
})(ActionType || (ActionType = {}));

var Mixed;
(function (Mixed) {
    Mixed[Mixed["A"] = 0] = "A";
    Mixed[Mixed["B"] = 1] = "B";
    Mixed["C"] = "hi";
    Mixed[Mixed["D"] = 10] = "D";
    Mixed[Mixed["E"] = 11] = "E";
    Mixed["F"] = "bye";
})(Mixed || (Mixed = {}));

Actual behavior:

var ActionType;
(function (ActionType) {
    ActionType[ActionType["AddUser"] = "ADD_USER"] = "AddUser";
    ActionType[ActionType["DeleteUser"] = "DELETE_USER"] = "DeleteUser";
    ActionType[ActionType["RenameUser"] = "RENAME_USER"] = "RenameUser";
})(ActionType || (ActionType = {}));

var Mixed;
(function (Mixed) {
    Mixed[Mixed["A"] = 0] = "A";
    Mixed[Mixed["B"] = 1] = "B";
    Mixed[Mixed["C"] = "hi"] = "C";
    Mixed[Mixed["D"] = 10] = "D";
    Mixed[Mixed["E"] = 11] = "E";
    Mixed[Mixed["F"] = "bye"] = "F";
})(Mixed || (Mixed = {}));
@RyanCavanaugh
Copy link
Member

Can you share more of your configuration? I'm not seeing this

C:\Throwaway>type q.ts
enum ActionType {
    AddUser = "ADD_USER",
    DeleteUser = "DELETE_USER",
    RenameUser = "RENAME_USER"
}

C:\Throwaway>type q.js
var ActionType;
(function (ActionType) {
    ActionType["AddUser"] = "ADD_USER";
    ActionType["DeleteUser"] = "DELETE_USER";
    ActionType["RenameUser"] = "RENAME_USER";
})(ActionType || (ActionType = {}));

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Jun 27, 2017
@DanielRosenwasser
Copy link
Member

@RyanCavanaugh the question seems to be with respect to Mixed

@RyanCavanaugh
Copy link
Member

Reading fail 😢

@RyanCavanaugh
Copy link
Member

This is what I see

enum Mixed {
    A,
    B,
    C = "hi",
    D = 10,
    E,
    F = "bye"
}
var Mixed;
(function (Mixed) {
    Mixed[Mixed["A"] = 0] = "A";
    Mixed[Mixed["B"] = 1] = "B";
    Mixed["C"] = "hi";
    Mixed[Mixed["D"] = 10] = "D";
    Mixed[Mixed["E"] = 11] = "E";
    Mixed["F"] = "bye";
})(Mixed || (Mixed = {}));

@StrahilKazlachev
Copy link
Author

StrahilKazlachev commented Jun 27, 2017

@RyanCavanaugh My mistake not properly explaining - not just for mixed(used it as a ready example). When you asked for configuration I thought that I may have misconfigured VSCode, or was mislead by it, - local rc for editing support, VSCode own version for the build task. I can't check till tomorrow though.

@StrahilKazlachev
Copy link
Author

My mistake, the out-of-the-box build task used a different different version of TS. Don't know why the output console did not auto show.

@RyanCavanaugh RyanCavanaugh added External Relates to another program, environment, or user action which we cannot control. and removed Needs More Info The issue still hasn't been fully clarified labels Jun 28, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

3 participants