Generation of enums

Issue #12 resolved
Sébastien
created an issue

Enums are not correctly generated.

For this enum

    public class MyClass
    {
        public MyEnum EnumProp { get; set; }
    }
    public enum MyEnum
    {
        Open = 1,
        Closed = 2,
    }

TypeLite generates this Typescript

module System {

interface Enum {
}
}
interface MyClass{
   EnumProp: MyEnum
}
interface MyEnum extends System.Enum {
}

A better way to generate the enum would be like

interface MyClass{
   EnumProp: number
}
export class MyEnum{
   static Open = 1;
   static Close = 2;
}

TypeScript/TypeLite will need to generate a second file. This would be a javascript file with all enum types.

This change would be very interresting so we don't need to use numbers in our typescript code.

Example:

export class MyViewModel
{
   EnumProp: MyEnum;
   public MyTypescriptMethod()
   {
      if (this.EnumProp === MyEnum.Open)
      {
         // some code
      }
      // flaggable enums
      if ((this.EnumProp & MyEnum.Open) === MyEnum.Open)
      {
         // some code
      }
   }
}

I hope you get the idea. :-)

Comments (8)

  1. Lukas Kabrt repo owner

    Right now I am going through the specification of TypeScript 0.9 and It contains a new style of enum declarations. I hope it will be possible to use this new style in TypeLite.

  2. bastiaan_van_drongelen

    Hi Lukas,

    Great initiative, I really like the idea! However, like Bert said, we need the enums to work in order to use it in our projects. Any progress on fixing this issue? If not, I would be happy to fix it this weekend..

    Keep up the good stuff! Bastiaan

  3. Lukas Kabrt repo owner

    Thank you for a support :-).

    I am working on the next version, that will add support for enums, but I don't have as much time as I want to work on this project.

    Tomorrow I will push code I have and I will be happy to accept any help.

  4. Log in to comment