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 enum computed values not allowed #20440

Closed
michaelgeorgeattard opened this issue Dec 4, 2017 · 4 comments
Closed

String enum computed values not allowed #20440

michaelgeorgeattard opened this issue Dec 4, 2017 · 4 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@michaelgeorgeattard
Copy link

michaelgeorgeattard commented Dec 4, 2017

TypeScript Version: 2.7.0-dev.201xxxxx

Code

As mentioned earlier by @MadaraUchiha and others, why can we do the following?

const Foo = 0;

enum MyEnum {
    FooValue = Foo,
}

But not:

const Foo = "0";

enum MyEnum {
    FooValue = Foo,
}

It should be either both are valid, or none, this looks like an inconsistency in Typescript.

@mhegazy
Copy link
Contributor

mhegazy commented Dec 4, 2017

Should be addressed by #18887

@mhegazy mhegazy assigned ghost Dec 4, 2017
@mhegazy mhegazy added the Suggestion An idea for TypeScript label Dec 4, 2017
@ghost ghost added the Fixed A PR has been merged for this issue label Dec 6, 2017
@martabrzeszczyk
Copy link

martabrzeszczyk commented Jun 11, 2018

@andy-ms Is it still going to be fixed? #18887 suggests that only conflicts needs to be resolved?

@pgraham
Copy link

pgraham commented Aug 8, 2018

#18887 was automatically closed due to inactivity, is this going to fixed?

@RyanCavanaugh RyanCavanaugh removed Fixed A PR has been merged for this issue Suggestion An idea for TypeScript labels Aug 22, 2018
@RyanCavanaugh RyanCavanaugh unassigned ghost Aug 22, 2018
@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Aug 22, 2018
@RyanCavanaugh
Copy link
Member

This is disallowed on purpose.

String enums are syntactically differentiated from numeric enums by having string literals in all initialization positions. It's also the case that we need to produce a union type (instead of a branded primitive type) for a string literal enum, which aren't really sourced from consts without explicit type annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants