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

Use const enum values in enum declarations member initializer. #1797

Closed
mpawelski opened this issue Jan 25, 2015 · 4 comments
Closed

Use const enum values in enum declarations member initializer. #1797

mpawelski opened this issue Jan 25, 2015 · 4 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Spec Issues related to the TypeScript language specification

Comments

@mpawelski
Copy link

Right now we can write code like this in C#:

enum EnumA
    {
        Foo = 1
    }

    enum EnumB
    {
        Foo = EnumA.Foo,
        Bar = 1
    }

and in Typescript we can simulate that with this code:

enum EnumA {
    Foo = 1
}

enum EnumB {
    Foo = <number>EnumA.Foo,
    Bar = 1
}

and everything work fine (just EnumB.Foo isn't inlined, but it is not a big problem).

It would be nice if we could do something like this with const enums:

const enum EnumA {
    Foo = 1
}

const enum EnumB {
    Foo = EnumA.Foo,
    Bar = 1
}

It would be similar to what we can do right now in C# enums. Personally, want this feature because I want my declared enums in TypeScript (API client) to be exactly like those in C# code (API server), but I think it would be useful for others too. Besides, current error In 'const' enum declarations member initializer must be constant expression. is a little funny because cons enum values are constant expressions in mu opinion ;)

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Spec Issues related to the TypeScript language specification labels Jan 26, 2015
@RyanCavanaugh
Copy link
Member

Seems reasonable to add "previously-declared const enum members" the list of things we consider valid for const enum member initializers

@vladima
Copy link
Contributor

vladima commented Jan 26, 2015

Agree, this looks like a nice change to make

@ghost
Copy link

ghost commented Mar 21, 2015

I think this should be closed?

@RyanCavanaugh
Copy link
Member

Seems so.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Mar 23, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Spec Issues related to the TypeScript language specification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants