Skip to content

String enum computed values not allowed #20440

Closed

Description

TypeScript Version: 2.7.0-dev.201xxxxx

Code

As mentioned earlier by Madara Uchiha (@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.

Activity

  1. mhegazy commented on Dec 4, 2017

    @mhegazy
    Contributor

    Should be addressed by #18887

  2. ghost added
    FixedA PR has been merged for this issue
    on Dec 6, 2017
  3. martabrzeszczyk commented on Jun 11, 2018

    @martabrzeszczyk

    Andy (Andrewkraft) (@Andy-MS) Is it still going to be fixed? #18887 suggests that only conflicts needs to be resolved?

  4. pgraham commented on Aug 8, 2018

    @pgraham

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

  5. RyanCavanaugh commented on Aug 22, 2018

    @RyanCavanaugh
    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.

  6. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions