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

Difference between 1.4 and 1.5 in generating JavaScript for enums in declared modules #3548

Closed
ArtemGovorov opened this issue Jun 18, 2015 · 2 comments
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead

Comments

@ArtemGovorov
Copy link

For the code like this:

declare module M {
    export enum E {
        V = 1
    }
}

var a = M.E.V;

1.4 generates

var a = 1 /* V */;

1.5 generates

var a = M.E.V;

Is it expected?

@danquirk
Copy link
Member

Yes, that's intended. See http://stackoverflow.com/questions/28818849/how-do-the-different-enum-variants-work-in-typescript, in particular the end:

_Changes in TypeScript

Between TypeScript 1.4 and 1.5, there was a change in the behavior (see #2183) to make all members of non-declare non-const enums be treated as computed, even if they're explicitly initialized with a literal. This "unsplit the baby", so to speak, making the inlining behavior more predictable and more cleanly separating the concept of const enum from regular enum. Prior to this change, non-computed members of non-const enums were inlined more aggressively._

@danquirk danquirk added the By Design Deprecated - use "Working as Intended" or "Design Limitation" instead label Jun 18, 2015
@splintor
Copy link

But #2183 explicitly says:

Ambient non-const enums preserve existing behavior (computed iff there is no initializer)

And this problem is about ambient (declared) non-const enums. In 1.5, they are treated as computed and are not inlined.

splintor added a commit to splintor/Proto2TypeScript that referenced this issue Jun 21, 2015
In order to avoid issues like
microsoft/TypeScript#3548, it seems better to
generate const enums.
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead
Projects
None yet
Development

No branches or pull requests

3 participants