Skip to content

Add downlevel and typing support for const enum members in computed properties #1844

Closed

Description

const enum E {
    x
}

var v = {
    [E.x]: ""
};

There are two things we can do by taking advantage of our static knowledge of const enums. One is that we can downlevel this without using an element access:

var v = {
    0: ""
};

Another is that we can know the type of v. Specifically, we know that it has a property named 0 of type string, which we would not know if this were not a const enum member.

Activity

  1. added
    DeclinedThe issue was declined as something which matches the TypeScript vision
    and removed on May 4, 2015
  2. RyanCavanaugh commented on May 4, 2015

    @RyanCavanaugh
    Member

    Not terribly useful with numeric names. We should revisit this when we have string-based enums, where this would be more useful

  3. JsonFreeman commented on May 4, 2015

    @JsonFreeman
    ContributorAuthor

    It is useful if you do not care about what number the name evaluates to, and you just want to think of the property as being keyed by the enum member itself, much like a property keyed by a symbol.

  4. danquirk commented on May 5, 2015

    @danquirk
    Member

    Tagging #1206 so we actually can maybe revisit this

  5. locked and limited conversation to collaborators on Jun 18, 2018
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

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions