{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3572","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3572/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3572/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3572/events","html_url":"https://github.com/Microsoft/TypeScript/issues/3572","id":89591621,"number":3572,"title":"const enum: numeric name","user":{"login":"jbondc","id":199519,"avatar_url":"https://avatars.githubusercontent.com/u/199519?v=3","gravatar_id":"","url":"https://api.github.com/users/jbondc","html_url":"https://github.com/jbondc","followers_url":"https://api.github.com/users/jbondc/followers","following_url":"https://api.github.com/users/jbondc/following{/other_user}","gists_url":"https://api.github.com/users/jbondc/gists{/gist_id}","starred_url":"https://api.github.com/users/jbondc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbondc/subscriptions","organizations_url":"https://api.github.com/users/jbondc/orgs","repos_url":"https://api.github.com/users/jbondc/repos","events_url":"https://api.github.com/users/jbondc/events{/privacy}","received_events_url":"https://api.github.com/users/jbondc/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-06-19T15:25:53Z","updated_at":"2015-06-19T17:24:13Z","closed_at":"2015-06-19T17:24:13Z","body":"```\r\nconst enum foo {\r\n\tNaN = 1, // error: An enum member can not have a numeric name\r\n\tInfinity = 2 // error: An enum member can not have a numeric name\r\n}\r\n```\r\nDon't think those should be errors.\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/113581134","html_url":"https://github.com/Microsoft/TypeScript/issues/3572#issuecomment-113581134","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3572","id":113581134,"user":{"login":"DanielRosenwasser","id":972891,"avatar_url":"https://avatars.githubusercontent.com/u/972891?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielRosenwasser","html_url":"https://github.com/DanielRosenwasser","followers_url":"https://api.github.com/users/DanielRosenwasser/followers","following_url":"https://api.github.com/users/DanielRosenwasser/following{/other_user}","gists_url":"https://api.github.com/users/DanielRosenwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielRosenwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielRosenwasser/subscriptions","organizations_url":"https://api.github.com/users/DanielRosenwasser/orgs","repos_url":"https://api.github.com/users/DanielRosenwasser/repos","events_url":"https://api.github.com/users/DanielRosenwasser/events{/privacy}","received_events_url":"https://api.github.com/users/DanielRosenwasser/received_events","type":"User","site_admin":false},"created_at":"2015-06-19T17:24:13Z","updated_at":"2015-06-19T17:24:13Z","body":"This has nothing to do with `typeof`. This has to do with the fact that when indexing with a value equal to `NaN` (e.g. `0/0`), you are actually indexing with `\"NaN\"`. If we don't check to make sure an enum name is numeric, then the reverse-mapping no longer applies - in the following example, even though the expression indexed with is of type `number`, you'll get `10` (which is also a `number`) instead of `\"A\"`.\r\n\r\n```TypeScript\r\nenum E {\r\n\tA = NaN,\r\n\tNaN = 10,\r\n}\r\n\r\nE[0/0];\r\n```\r\n\r\nBasically what we look for is whether the abstract operation `ToNumber` and then `ToString` matches the text of the enum name. See [the explicit logic](https://github.com/Microsoft/TypeScript/blob/f2044a901165a2a97813772353b57dd9ed4796ca/src/compiler/checker.ts#L6555). See the comment that precedes it.\r\n\r\nWhether or not it matters for `const enum`s is arguable. Considering you can still have a reverse mapping with `--preserveConstEnums`, and that it's undesirable to have too many semantic differences between enums and const enums, I'm inclined to say that this is by design unless there's a sufficiently useful use case."}}