Skip to content

Using Enum in a separate file, inconsistently compiles on save vs project build #2422

Closed
@amg-argh

Description

@amg-argh

When creating and using an enum (TypeScript 1.4, Visual Studio 2013). When I build the project the enum value is compiled to a number, but if I save the file the compiled output is the full name of the enum. For example:

// enum.ts
enum SomeEnum {
    One = 1,
    Two = 2
}
// consumer.ts
class Consumer {
    public doSomething(): void {
        var x: SomeEnum = SomeEnum.One;
    } 
} 

When the project is built, it compiles to:

var Consumer = (function () {
    function Consumer() {
    }
    Consumer.prototype.doSomething = function () {
        var x = 1 /* One */;
    };
    return Consumer;
})();

However when I edit and save "consumer.ts" it compiles to:

var Consumer = (function () {
    function Consumer() {
    }
    Consumer.prototype.doSomething = function () {
        var x = SomeEnum.One;
    };
    return Consumer;
})();

The issue is that the enum values are sitting in a DomainModels.d.ts file (that is converted from C# using TypeLite). So the definition of the enum is never included in the output.

The preferred output would be always compiling to a number.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions