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

Const enums should be considered compile-time constants for computed property names #10770

Closed
JoshuaKGoldberg opened this issue Sep 8, 2016 · 1 comment
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@JoshuaKGoldberg
Copy link
Contributor

TypeScript Version: 1.8.0

Code

const enum Color {
    Blue,
    Red = 1
}

interface IColors {
    // Error: A computed property name in an interface must be a compile-time constant
    [Color.Blue]: any;
    [Color.Red]: any;

    // No errors thrown
    [2]: any;
}

Expected behavior:
No red squigglies

Actual behavior:
Red squigglies, because a const enum's value isn't considered a compile-time constant (isn't it?).

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Sep 8, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Sep 8, 2016

this is a duplicate of #5579.

The issue here is not that they are constants or not. the issue is that the way the compiler is layered, it does not necessary know what they are when a it forms the shape of the internal data structure representing the interface or class (symbol). see #5579 for more details.

@mhegazy mhegazy closed this as completed Sep 8, 2016
@mhegazy mhegazy added Duplicate An existing issue was already created and removed In Discussion Not yet reached consensus labels Sep 8, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants