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

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

Closed
JsonFreeman opened this issue Jan 29, 2015 · 3 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@JsonFreeman
Copy link
Contributor

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.

@JsonFreeman JsonFreeman added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Jan 29, 2015
@RyanCavanaugh RyanCavanaugh added Declined The issue was declined as something which matches the TypeScript vision and removed In Discussion Not yet reached consensus labels May 4, 2015
@RyanCavanaugh
Copy link
Member

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

@JsonFreeman
Copy link
Contributor Author

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.

@danquirk
Copy link
Member

danquirk commented May 5, 2015

Tagging #1206 so we actually can maybe revisit this

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants